I use of codeigniter and class (library) pagination in it, why after each click on pagination in column #, be counted rows from the beginning.
I want like this( p = pagination ):
p1-> #-> 1 2 3
p2-> #-> 4 5 6
p3 -> #-> 7 8 9
p4 #-> 10
EXAMPLE: see example of my problem.
For see full code go to here: FULL CODE
$data['results'] = $this->db->query("SELECT @rownum:=@rownum+1 rownum, t.*
FROM (
SELECT *
FROM hotel_submits
ORDER BY id desc
LIMIT $offset, 3
) t,
(SELECT @rownum:=0) r");
Rownum in top code is the associated with this problem.
You know how to solve this problem?
Can you retrieve the
$offsetfor the page you are currently on?Like if I am on page 1,
$offset= 1,if I am on page 2,
$offset= 4 (1 + (page 2 – 1) * 3)if I am on page 3,
$offset= 7 (1 + (page 3 – 1) * 3)etc.
If you can’t readily get that at the moment, you can pass it from your controller so your view is aware of the current
$offset.Then in your code, instead of using
$row->rownum, add the value of the current$offsetminus 1 since rownum starts 1.So on page 2, instead of 1, 2, 3 etc, it should be (1+4-1) 4, (2+4-1) 5, (3+4-1) 6.
I hope that makes sense.