I use a table class that automatically generates a table for me from an array of data extracted 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')); }
Ultimately, the controller will be moved to view mode when it is running. This creates a table just fine, but I would like to add a link to the field. For example, an id column that will allow me to link to a data page for that report identifier only. I know that I can simply display the table in the old-fashioned way manually. Then I can add any links that I need, but I would like to use auto-generation as much as possible. There must be a way to do something as general as binding a table cell. Does anyone have any ideas?
EDIT
The Java PHP user has it basically right below. Here is 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 text version.
source share