Problem with counter in table |
I need to insert an auto incrementing number in a table.
The model is: PHP Code: public function players($limit, $offset) { The controller is: PHP Code: public function players($offset = 0) { The template is: PHP Code: {foreach $variable as $data} The template is in smarty template. How can I insert an auto incrementing number that continues to increase with changing page? And it can set within that foreach? Sorry for the inconvenience, but I just can not figure out how. Thanks for the answers.
Hi.
For me is a bit confusing what kind of auto incrementing field you want. You need something like the order number for the list of players that is persistent through all the pages? Like this? Page 1: 1. Player1 2. Player2 ... 25. Player25 Page 3: 51. Player51 52. Player52 and so on? If this is your case, then you can add the offset parameter to the template data in your controller: PHP Code: public function players($offset = 0) { Then simply do addition in your template: PHP Code: {foreach $variable as $index => $data} Not sure it'll work well with smarty syntax, because I'm not that familiar with it. But still you should get the idea.
Wow
![]() Can you explain to me what means $index?
Sure.
$index is the variable that will hold the numerical position of the element in array. Your PHP Code: array($player1, $player2, ... $playerN) is actually something like the PHP Code: array(0 => $player1, 1 => $player2, ... N - 1 => $playerN) So you can just grab that position into the $index variable in the foreach expression. Also because of the arrays start from 0 you need that +1 thing in the template.
|
Welcome Guest, Not a member yet? Register Sign In |