View Full Version : Resolved Next and Previous ID's from a table

03-01-2010, 12:50 AM
I need to get the previous and next ID's from a table. The table has a group that they are in as well. I have the following code, but it will only pull the ID of the current page.

$sqlnext = mysql_query ("SELECT * FROM tutorials WHERE id > '$id' AND series='$series' ORDER BY id LIMIT 1");
$rownext = mysql_fetch_array ($sqlnext);
$nextid = $row['id'];
$nextname = $row['name'];
if((!empty($nextid)) && ($nextid != $id))
$next="<a href=\"./$basepage?page=tutorials&command=view&id=$nextid\">$nextname</a>";

I can offer more code if needed.

03-01-2010, 01:08 AM
$nextid = $row['id']+1;

Try that?

03-01-2010, 01:17 AM
No, because it won't work the way I need it to.

The table will have multiple groups or series. SO id+1 is likely to be in a different series, or hidden.

03-01-2010, 04:12 AM
I found what was wrong... just a typo. I forgot to change it to $nextid = $rownext['id']; causing it to use the prior query instead.