Display an incrementing number in each row when using table class

I want to display an incrementing number in each row by using table class


1 column1 column2
2 column1 column2
3 column1 column2
4 column1 column2

how can i do that. I'm new, therefore explain little bit more

thanx in advance

when you are building the array for the table, just add the extra column with the number

$data = array(
             array(1, 'Name', 'Color', 'Size'),
             array(2, 'Fred', 'Blue', 'Small'),
             array(3, 'Mary', 'Red', 'Large'),
             array(4, 'John', 'Green', 'Medium')

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

I forgot to mention that i'm taking data from the database table

Then I wouldn't recommend using the table class, generate it yourself
//in the view
    $no = 1;
    foreach($item_list as $item){
        <td>&lt;?php echo $nr; ?&gt;</td>
        <td>&lt;?php echo $item['item_1']; ?&gt;
        <td>&lt;?php echo $item['item_2']; ?&gt;
        <td>&lt;?php echo $item['item_3']; ?&gt;
        <td>&lt;?php echo $item['item_4']; ?&gt;

Thanx. But I need a way to do that using codeigniter table class. Otherwise it is point less to use the table class. I have already used the table class.

Any ways, thanx for your support

one other way you could do it, change function in the the model to this
$query = $this->db->get('mytable');

$nr = 1;
$data = "";
foreach ($query->result() as $row)
    $data[] = array('no' => $nr, 'value' => $row->item_1);

return $data;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.