Solarpitch Posted March 1, 2008 Share Posted March 1, 2008 Hey, I have a series of articles on my site that are being pull from the database. When the user select an article I want to have a "Next Article" button that will take them to the next article, then if there at the last article and they click next article it will simply bring them back to the first article again. Here's what I was trying which works to some extent but not the full functionality. <?php // SNIPPET OF CODE $sql = "select * from articles where article_id = ".$article_id.""; $result = mysql_query($sql) or die(mysql_error()); while(($row = mysql_fetch_row($result)) != false) { $next_article = article_id + 1; if(!result) { $next_article= $story_id; } // ............... <a href='articles.php?id=".$next_article."'></a> ?> Link to comment https://forums.phpfreaks.com/topic/93870-a-link-to-next-result-in-database/ Share on other sites More sharing options...
AndyB Posted March 1, 2008 Share Posted March 1, 2008 In a normal database with auto-incrementing ids, there's no guarantee that the 'next' and 'previous' numerical records would exist. next higher is SELECT article_id from articles WHERE article_id>'$current_id' ORDER by article_id DESC LIMIT 1 next lower is SELECT article_id from articles where article_id<'$current_id ORDER by article_id ASC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/93870-a-link-to-next-result-in-database/#findComment-481068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.