Jump to content

Making a Next Link


Canman2005

Recommended Posts

Hi all

 

I have this code

 

SELECT mass FROM items WHERE id = ".$_GET['pr']." AND cats = ".$_GET['ca']."

 

That does a QUERY and returns details of 1 row.

 

What I want to do is to create a "next" link on my page, so basically I need to be able to grab the next rows ID number in the sequence, so that I can create a "next" link.

 

Further to this, is it possible that when it reaches the last ID number in the sequence, it then grabs the 1st ID number in the sequence, so that I can create a kind of never ending loop on my "next" link.

 

I do have a code to kind of do this, but it's massive and bulky and does page numbering rather than just a "next" link, and I want to try and use something very simple and quick to load.

 

Can anyone help?

 

Thanks very much in advance

 

Dave

Link to comment
Share on other sites

method 1:

run a query that grabs all ids.  Store ids in a session array. (only run query if session array doesn't exist, so it's not being run every page load).  Use next to get the next id in the array and run your query off that.  Wrap it in a condition.  If next returns false, use reset instead of next and run your query off that.

 

method 2:

user presses the next link, run a query where id > current id, ordering by id asc limit 1.  wrap it around a condition.  If 0 results are returned, run a query ordering by id asc limit 1 to get first id.

 

 

Link to comment
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.