mcmuney Posted January 23, 2008 Share Posted January 23, 2008 I have a page that displays and image based on the id specified on the URL. What i'd like to do is add a previous and next link from that id. I've created the code below, which was working fine. BUT the problem occurs when a row is deleted, it assumes there's no next record. For example, if the DB has records 1,2,3,6,7 and the user is viewing image 2, then the next button will show image 3, but then it will disappear because 4 is NULL. I need it to go to 6 from 3. How can I take the next id rather then specifying $id+1? <?/* $next = $id+1; $sql3 = mysql_query("SELECT * FROM images WHERE id='$next'"); $row3 = mysql_fetch_array($sql3); $date3 = $row2[date]; $tag3 = $row2[tags]; if ($row3!=NULL){ echo "<a href='/pic.php?d=".$date3."&id=".$next."'><img src='/images/arrowright.gif' border='0' alt='".$tag3."'></a>"; } */?> Link to comment https://forums.phpfreaks.com/topic/87315-solved-previous-and-next/ Share on other sites More sharing options...
Ken2k7 Posted January 23, 2008 Share Posted January 23, 2008 1. What's $row2[tags]? 2. You would just loop and check if the value at that ID is null. Link to comment https://forums.phpfreaks.com/topic/87315-solved-previous-and-next/#findComment-446588 Share on other sites More sharing options...
mcmuney Posted January 23, 2008 Author Share Posted January 23, 2008 1. That should be $row3 (good catch) 2. How would that look? Link to comment https://forums.phpfreaks.com/topic/87315-solved-previous-and-next/#findComment-446610 Share on other sites More sharing options...
sasa Posted January 23, 2008 Share Posted January 23, 2008 try //$next = $id+1; remove this line $sql3 = mysql_query("SELECT * FROM images WHERE id>'$id' ORDER BY id ASC LIMIT 1"); $row3 = mysql_fetch_array($sql3); etc. } Link to comment https://forums.phpfreaks.com/topic/87315-solved-previous-and-next/#findComment-446619 Share on other sites More sharing options...
mcmuney Posted January 23, 2008 Author Share Posted January 23, 2008 I feel dumb now, thanks!!! Link to comment https://forums.phpfreaks.com/topic/87315-solved-previous-and-next/#findComment-446699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.