Pezmc Posted January 29, 2009 Share Posted January 29, 2009 Trying to create the good old "previous" and "next" buttons in PHP for a database of news. News is just taken from the database where the ID posted (get) is equal to the ID and published = 1 (whether its online) Say I have this database Id Title Published 1 News Item 1 3 News Item 1 6 News Item 0 7 News Item 1 9 News Item 1 How if the current id is 1 can I show only next and link to id 3? or if the ID is 3 show previous (linking to one) and next linking to 7 or if the ID is 7 show previous (linking to three) and next linking to 9 or if 9 show just previous (linking to 7) Sorry rather hard concept to explain! Hope you can help! Quote Link to comment https://forums.phpfreaks.com/topic/142996-getting-next-valid-row-and-previous-if-exists/ Share on other sites More sharing options...
Maq Posted January 29, 2009 Share Posted January 29, 2009 I think you're referring to pagination. Here is a great tutorial on the basics! Quote Link to comment https://forums.phpfreaks.com/topic/142996-getting-next-valid-row-and-previous-if-exists/#findComment-749843 Share on other sites More sharing options...
Pezmc Posted January 30, 2009 Author Share Posted January 30, 2009 Thanks! Got it to work with: Query to get previous id : "SELECT id FROM TABLENAME WHERE id < $currentId order by id DESC LIMIT 1" (it will return 3) Query to get next id : "SELECT id FROM TABLENAME WHERE id > $currentId order by id LIMIT 1" (it will return 6) Quote Link to comment https://forums.phpfreaks.com/topic/142996-getting-next-valid-row-and-previous-if-exists/#findComment-750275 Share on other sites More sharing options...
Maq Posted January 30, 2009 Share Posted January 30, 2009 great, mark as SOLVED please. Quote Link to comment https://forums.phpfreaks.com/topic/142996-getting-next-valid-row-and-previous-if-exists/#findComment-750607 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.