开发者

Adding auto increment column in table in codeigniter

开发者 https://www.devze.com 2023-03-29 23:12 出处:网络
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 (

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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消