Jump to content

Recommended Posts

Ok... here's a question. On forums like phpBB, vBulletin, invision, (and probably this one), when viewing a topic... there's links at the top of it that give you an option to go to "The next topic" in that forum.

 

Well, the topic your own might have an id of 105, and the next one in the forum might be 109, so my question is:

 

How do I find the next, and previous items in a mysql query, when I format my query such as:

 

$query = "SELECT * FROM photos WHERE photo_id='105'";
$result = mysql_query($query);

 

I want to be able to find the next and previous photo_id in the same album...

 

Some help please? :)

Link to comment
https://forums.phpfreaks.com/topic/66381-next-previous-results/
Share on other sites

Its Called Pagination.

 

Here is a good tutorial on it...http://php.about.com/od/phpwithmysql/ss/php_pagination.htm

 

edit: Or why don't you search this website for a tutorial. On the main page that is....

 

I'm well aware of how to program paging... but how do you make a "next photo" while displaying the current information of one ... ?

Link to comment
https://forums.phpfreaks.com/topic/66381-next-previous-results/#findComment-332200
Share on other sites

You will have to know how the topics are organized. The reason the numbres jump is probably because 106, for example, might be in a different section (This is how mine works, at least.) When you make your query, you need to check the section id against the current one, something like:

"SELECT topicid FROM topics WHERE topicid > $currenttopicid AND sectionid = $currentsectionid ORDER BY topicid LIMIT 1"

 

Something like that should do it.

Link to comment
https://forums.phpfreaks.com/topic/66381-next-previous-results/#findComment-332202
Share on other sites

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.