Canman2005 Posted April 27, 2009 Share Posted April 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155788-making-a-next-link/ Share on other sites More sharing options...
Canman2005 Posted April 27, 2009 Author Share Posted April 27, 2009 ? anyone ? can you help Quote Link to comment https://forums.phpfreaks.com/topic/155788-making-a-next-link/#findComment-820145 Share on other sites More sharing options...
chmpdog Posted April 27, 2009 Share Posted April 27, 2009 whats the key in the database? if its id just do $id++; echo "<a href='?".$id."'>next</a>" Quote Link to comment https://forums.phpfreaks.com/topic/155788-making-a-next-link/#findComment-820276 Share on other sites More sharing options...
.josh Posted April 27, 2009 Share Posted April 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155788-making-a-next-link/#findComment-820279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.