Jump to content

previous/next problems


ianco

Recommended Posts

Hi all,

 

I'm trying to implement previous and next buttons on a blog.

 

The problem is that the next and previous id just gives the highest and lowest values, respectively.

 

I got the query from a site but it's the implementation I'm finding tricky.

 

Any ideas where i'm going wrong?

 

Ian

 

$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$currentTopicId = $_GET['BlogID'];


$qp = mysql_query("SELECT BlogID FROM Blog WHERE BlogID < $currentTopicId ORDER BY BlogID ASC LIMIT 1") or die(mysql_error());
while(
$rowp = mysql_fetch_assoc($qp)
){

echo "<a class='left' href='blog.php?BlogID=" .  $rowp['BlogID'] . "'>Previous</a>";

}

$qn = mysql_query("SELECT BlogID FROM Blog WHERE BlogID > $currentTopicId ORDER BY BlogID DESC LIMIT 1") or die(mysql_error());
while(
$rown = mysql_fetch_assoc($qn)){

echo "<a class='right' href='blog.php?BlogID=" . $rown['BlogID'] . "'>Next</a>";
}

Link to comment
https://forums.phpfreaks.com/topic/218866-previousnext-problems/
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.