Reputation: 1
I am new to codeigniter. In my project I am getting some data from database and then showing them using codeigniter table->generate method. But I want to add an autoincrement column (like 1,2,3..) to show the row number in an additional column at the left of the table. Also, beside the number there will be checkbox to mark the row. Can anybody give me idea how can I do it in codeigniter?
Upvotes: 0
Views: 2243
Reputation: 2321
You could add a count to your SQL query so that it is returned along with your results:
SET @n=0; SELECT @n := @n+1, * FROM example_table
Alternatively you could add the count to each result in PHP:
$count = 1;
foreach($results as $key => &$result){
array_push($result, $count);
$count++;
}
echo $this->table->generate($results);
Upvotes: 1