HokieTracks Posted April 12, 2009 Share Posted April 12, 2009 Hi, I currently have a database full of news entrys. Too display the latest news entry I use this code: <?php require('connect.php'); //Defines $query_photos as getting everything from photo $query_news = "SELECT * FROM photo ORDER BY id DESC LIMIT 1"; //defines news as running the above $news = mysql_query($query_news) or die(mysql_error()); $row_news = mysql_fetch_assoc($news); //numbers rows as variable $totanews $totalnews = mysql_num_rows($news); //if there are no rows, then there is no news under that ID. if ($totalnews == '0') { echo '<script>alert("No news here under this id");</script>'; echo '<script>history.back(1);</script>'; } //otherwise write the news title and underneath the news content else { echo $row_news['title'];?> <br/><br/> <?php echo $row_news['content']; ?> <?php } ?> What I want to do now is create next and previous links that will take the user to the previous news entry or the next news entry in the database. Any ideas about how I can do this? Link to comment https://forums.phpfreaks.com/topic/153701-view-previous-and-next-databse-entry/ Share on other sites More sharing options...
HokieTracks Posted April 12, 2009 Author Share Posted April 12, 2009 Anyone? Link to comment https://forums.phpfreaks.com/topic/153701-view-previous-and-next-databse-entry/#findComment-807871 Share on other sites More sharing options...
Anxious Posted April 12, 2009 Share Posted April 12, 2009 Ignore the 'next' news article, if that code you have there displays the LATEST news, it'd be rather pointless. I have no idea what to do, you would be needing to edit the top code, where it selects the article from the database. Nobody seems to be replying on this forum much being probably because its easter. I really could do with help on my thread. Link to comment https://forums.phpfreaks.com/topic/153701-view-previous-and-next-databse-entry/#findComment-807874 Share on other sites More sharing options...
HokieTracks Posted April 12, 2009 Author Share Posted April 12, 2009 I need the next button for one a user has used the previous button. So basically the next button would only appear when the user is 2, 3, 4, 5, etc. articles deep into the news. Link to comment https://forums.phpfreaks.com/topic/153701-view-previous-and-next-databse-entry/#findComment-807876 Share on other sites More sharing options...
Anxious Posted April 12, 2009 Share Posted April 12, 2009 Ah, Yeah. In the 'next' you'd need to add in an if statement to say that if there isn't any more news to display (user is at the most recent one) to kill the code. I have no idea how to do it. Just focus around the part that gets the article, and work out how it gets it, like if its grabbing the time published so the most recent time published, it will display that article maybe. Link to comment https://forums.phpfreaks.com/topic/153701-view-previous-and-next-databse-entry/#findComment-807883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.