I want a good solution for next and previous in a php script. The first thing Im think is that you do this when you go next:
select id from table where id > '$_GET[id]' limit 1;
But how can I figure out if Im on first or last record? I want to hide next button if its the last record etc. Then Im think something like this:
select id from table where id > '$_GET[id]' limit 2;
if(mysql_num_rows($q) != 1) echo $nextButton;
The problem with my solution here is when Im on the first record! How can I possible how many record I have over the o开发者_开发问答ne Im selecting? Is there a simple and good solution for this or must I use more than one query to find out?
You actually need to find the number of pages based on the number of rows per page you're displaying. This will help you calculate an offset to feed into your LIMIT clause.
You can find a tutorial here
As a side note:
Do NOT pass $_GET['id'] into your SQL query the way you are. You must at least run mysql_real_escape_string() against it first.
精彩评论