ianco Posted November 16, 2010 Share Posted November 16, 2010 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 More sharing options...
kickstart Posted November 16, 2010 Share Posted November 16, 2010 Hi Think you just have the ASC and DESC in the wrong queries. Swap them round and I think it will work. All the best Keith Link to comment https://forums.phpfreaks.com/topic/218866-previousnext-problems/#findComment-1135104 Share on other sites More sharing options...
ianco Posted November 16, 2010 Author Share Posted November 16, 2010 Haha, cheers for that. Just goes to show that it isnt a black art... Ian Link to comment https://forums.phpfreaks.com/topic/218866-previousnext-problems/#findComment-1135132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.