Much is written in various how-to sites about next and previous page navigation utilizing Limit to retrieve multiple rows of data and display them in chunks of 10 rows to a PHP page, as an example. This problem is subtly different.

For the site I am programming, all of the content for a given page is one record in a database. It is retrieved from the database using an id field. The Next Page/Previous Page navigation desired is to go to the record before or after the one currently displayed as a single web page.

The order by which these pages appear can vary based on sorting and other query criteria. It is a given that any query will return multiple rows. Presently, the data result returns data for url's used elsewhere on the page for navigation. The Next Page/Previous Page navigation is to supplement that.

How does one query the database to get the next or previous id of the id currently selected?

i think you are concerning yourself with the id's when you actually don't need them here, you know the order already

page 1
select * from table
limit 1 offset 0

page 2
select * from table
limit 1 offset 1

if you are doing ordering, just add the order by, and it will work the same

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.