Jump to content

Recommended Posts

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!

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.