Quilmes Posted June 6, 2007 Share Posted June 6, 2007 I am working on a real estate listing website. What I am trying to do is create a link on each listing's page that will go to the next listing. This would be easy if it was just the next listing, but I'm trying to make it go to the next listing that the user got in their search. How would I go about doing this??? Quote Link to comment https://forums.phpfreaks.com/topic/54427-solved-next-listing/ Share on other sites More sharing options...
per1os Posted June 6, 2007 Share Posted June 6, 2007 Store a list of the listing ids in a session variable in order. <?php session_start(); $_SESSION['search_listings'] = "5,7,9,4,6"; $current = 7; $listings = isset($_SESSION['search_listings'])?explode(",", $_SESSION['search_listings']):array(); for ($i=0;$i<count($listings)-1;$i++) { if ($current == $listings[$i]) { $next = isset($listings[$i+1])?'<a href=list.php?id=' . $listings[$i+1] . '>Next</a>':'End of listings'; $prev = isset($listings[$i-1])?'<a href=list.php?id=' . $listings[$i-1] . '>Prev</a>':'Beginning of listings'; } } ?> Something like that. Quote Link to comment https://forums.phpfreaks.com/topic/54427-solved-next-listing/#findComment-269157 Share on other sites More sharing options...
Psycho Posted June 6, 2007 Share Posted June 6, 2007 This is not much different from regular pagination techniques. Take a look at the two pagination tutorials available on this site. The one thing that might not be included with that is the fact that you will need to save the unique parameters of the query. For instance if the user sis a search for 4 bedroom, 2 bath listing then your query might look like this: SELECT * FROM listings WHERE bed=4 AND bath=2 You will need to save those two variables in some way: cookie, session or GET data. Then as you paginate through each page you would have your page counter which will indicate which record in the query to extract using LIMIT. SELECT * FROM listings WHERE bed=4 AND bath=2 LIMIT $record, 1 Quote Link to comment https://forums.phpfreaks.com/topic/54427-solved-next-listing/#findComment-269164 Share on other sites More sharing options...
Quilmes Posted June 6, 2007 Author Share Posted June 6, 2007 I went with frost110's method. Works perfect. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/54427-solved-next-listing/#findComment-269254 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.