Need method to seek next/previous records id without cycling through all records.
Posted
by
dqhendricks
on Stack Overflow
See other posts from Stack Overflow
or by dqhendricks
Published on 2010-12-31T20:44:01Z
Indexed on
2010/12/31
20:53 UTC
Read the original article
Hit count: 206
I am using MySQL and PHP.
I have a MySQL blog post result set with id fields, and publish_date fields. I display one blog post per page, and the script knows which blog post to display based on $_GET['id'], which correlates to each blog entry's id field. I would like to reference them by id in the url, because I would like each blog post to have a perminant url. I would like to order the blog posts by publish date (descending).
Now, on each page there will be next and previous links, which contain the $_GET['id'] value for the next and previous blog posts. How can I figure out what the id of the next and previous blog posts (determined by it's publish_date order) without cycling through each mysql result row? I can't mysql_data_seek(), because I do not know the row index of the current blog post id. I do not want to store a row index in a GET variable because the urls would no longer be perminant. I obviously cannot store the row index in a SESSION variable because then direct links to specific blog posts would have broken next and previous links.
Any suggestions would be greatly appreciated.
© Stack Overflow or respective owner