Jump to content

[SOLVED] Previous and Next


mcmuney

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.