Welcome Guest, Not a member yet? Register   Sign In
Table class question
#2

[eluser]pickupman[/eluser]
Yes, and yes.
Code:
$this->load->helper('url');
$this->load->library('table');

$this->table->set_heading('ID', 'Title', 'Link');

foreach($items as $row)
{
  $this->table->add_row($row->id, $row->title, anchor('page/'.$row->id, 'View'));
}

echo $this->table->generate();

//Or use this foreach loop
<table>
  <thead>
    <tr>
      <td>ID</td>
      <td>Title</td>
      <td>Link</td>
    </tr>
   </thead>
   <tbody>
     &lt;?php foreaach($items as $row) :?&gt;
      <tr>
         <td>&lt;?php echo $row->id;?&gt;</td>
         <td>&lt;?php echo $row->title;?&gt;</td>
         <td><a >id;?&gt;">View</a></td>
      </tr>
      &lt;?php endforeach;?&gt;
   </tbody>
  </table>
So it's about 5 lines of code using the table class, but all php. Or its several lines of html with a little bit of php. Depends on people's opinion of how much php should be in views.

EDIT: Some reason my code is being butchered.


Messages In This Thread
Table class question - by El Forum - 10-19-2010, 04:47 PM
Table class question - by El Forum - 10-19-2010, 05:40 PM
Table class question - by El Forum - 10-19-2010, 06:45 PM
Table class question - by El Forum - 10-19-2010, 07:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB