I’m using the table class that auto-generates a table for me from an array of data pulled from my database.
Model:
function get_reports_by_user_id($userid) { return $this->db->get_where('ss2_report',array('userid' => $userid))->result_array(); }
Controller:
function index() { echo $this->table->generate($this->mymodel->get_reports_by_user_id('1234')); }
The controller will eventually be moved to a view when I have it working. This generates the table just fine, but I’d like to add a link to a field. For example, the id column that would allow me to link to a page of data for just that report’s id. I know I can just output the table the old fashioned way by hand. I can then add whatever links I want, but I’d love to be able to use the auto-generation as much as possible. There’s got to be a way to do something as common as linking a table cell. Does anyone have any ideas?
EDIT:
User Java PHP has it mostly right below. Here’s the code that makes it work:
function get_reports_by_user_id($userid) { $rows = $this->db->get_where('ss2_report',array('userid' => $userid))->result_array(); foreach ($rows as $count => $row) { $rows[$count]['id'] = anchor('report/'.$row['id'],$row['id']); } return $rows; }
I just needed to replace the value in the original array with the anchor text version.
The only way is, in the function
get_reports_by_user_id(), you would loop through all the results and add the<a href>tag to the ids. Something like this:I don’t use CodeIgniter’s database library so I’m not sure of what format it returns
$rowsin, but the code above should give you the general idea of what you need to do.