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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.