Hi Batalf,
So I would run that again with different names for Previous records too?
So, I'd run 3 queries in total?
Thanks heaps!
Main Topics
Browse All TopicsHi All,
This is probably extremely simple, but I cant work it out.
I have build a site for a client, Under the 'collections' link this displays all records from that 'collection' in thumbnail form, clicking one of them passes the id in the URL to display that product. Now, I have done $next = $id + 1; but of course, if the next record has been deleted, it wont return anything. How can I write a loop to keep checking until it finds the next record and pass the id of that record though the URL?
Thanks in Advance,
Christian
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Glad I could help!
I just thought of another option which also should work.
What if you have a link like this:
id=$id&next=true
i.e. send the current id and a variable called "next" to the current page. Then you could perform the query for next or previous record there, a query like this:
if(isset($_GET['next'])){
$sql = "select id from yourTable where id>'$id' order by id limit 1";
$res = mysql_query($sql) or die ("Error in query: " . mysql_error());
if($inf = mysql_fetch_array($res)){ // A next record is found
$id= $inf["id"]; // Set $id to the next ID
}
}
The same rules should also been applied for a variable called "previous".
The advantage of this solution is that you don't have to make 3 queries on each page.
Business Accounts
Answer for Membership
by: BatalfPosted on 2005-04-14 at 01:46:02ID: 13779658
You only need one query:
$sql = "select id from yourTable where id>'$id' order by id limit 1";
$res = mysql_query($sql) or die ("Error in query: " . mysql_error());
if($inf = mysql_fetch_array($res)){ // A next record is found
$next = $inf["id"];
}
You search for the first id which is bigger than the variable $id. This is the next id in the table.
"yourTable" is just an example name.
Batalf