Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter Table Class: Add a Link From a Generated Cell
    primarykey
    data
    text
    <p>I'm using the table class that auto-generates a table for me from an array of data pulled from my database.</p> <p><strong>Model</strong>:</p> <pre><code>function get_reports_by_user_id($userid) { return $this-&gt;db-&gt;get_where('ss2_report',array('userid' =&gt; $userid))-&gt;result_array(); } </code></pre> <p><strong>Controller</strong>:</p> <pre><code>function index() { echo $this-&gt;table-&gt;generate($this-&gt;mymodel-&gt;get_reports_by_user_id('1234')); } </code></pre> <p>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 <code>id</code> 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?</p> <p><strong>EDIT</strong>:</p> <p>User <strong>Java PHP</strong> has it mostly right below. Here's the code that makes it work:</p> <pre><code>function get_reports_by_user_id($userid) { $rows = $this-&gt;db-&gt;get_where('ss2_report',array('userid' =&gt; $userid))-&gt;result_array(); foreach ($rows as $count =&gt; $row) { $rows[$count]['id'] = anchor('report/'.$row['id'],$row['id']); } return $rows; } </code></pre> <p>I just needed to replace the value in the original array with the anchor text version.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload