angryjohnny Posted July 4, 2008 Share Posted July 4, 2008 Hello, Right now I have a very simple page that displays 1 row from a table that holds about 200 rows. I have a next button that cycles through them. $prev = $id - 1; $next = $id + 1; <a href='template.php?id=$prev'>prev</a> <a href='template.php?id=$next'>next</a> As you can see its very simple. My problem, lets say I have a search function or a 'template02.php' page that only selects rows from the table that holds the name 'john' from the $name colum, which in this case holds 6 items that have the id numbers: 7, 9, 22, 44, 76 and 89. I want to make a 'next' and 'previous' link, that links to the respective item. Any Ideas? John Quote Link to comment Share on other sites More sharing options...
fenway Posted July 4, 2008 Share Posted July 4, 2008 Why not simply pass the current "position" and get the next/prev 5? Quote Link to comment Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 I'm not entirely sure what you mean but is this any help? SELECT id, (id-1) AS previous, (id+1) AS next FROM aTable Quote Link to comment Share on other sites More sharing options...
fenway Posted July 4, 2008 Share Posted July 4, 2008 I mean using the ID of the current one (which always exists) as a starting point, using LIMIT 5, and the ordering by something meaningful (_not_ the ID) in either DESC or ASC. Quote Link to comment 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.