Reputation: 3
i need a query that can display row number sequence when we have pagination. I have a problem the row number always the same when we click at next page or previous page. Please help! see hyperlink below.
$result=mysql_query("select @rownum:=@rownum+1 rownumber, t.* from tablekad t, (SELECT @rownum:=0) r order by tarikh asc LIMIT $start, $limit");
Page 2 <---- here the link for page 2 the problem
Can with a single query we can display correctly the row number when we click the next page or previous ? Any solution for this? Please help...
Upvotes: 0
Views: 1693
Reputation: 1269873
You can do what you want with a subquery:
select t.*
from (select @rownum:=@rownum+1 rownumber, t.*
from tablekad t cross join
(SELECT @rownum:=0) r
order by tarikh asc
) t
LIMIT $start, $limit;
Technically, you should probably repeat the order by
on the outer query. In practice, this is probably not necessary.
Upvotes: 1