Getting Next Valid Row and Previous if exists
Posted: Thu Jan 29, 2009 3:54 am
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!
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!