Jump to content

[SOLVED] Next Listing?


Quilmes

Recommended Posts

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???

Link to comment
https://forums.phpfreaks.com/topic/54427-solved-next-listing/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/54427-solved-next-listing/#findComment-269157
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/54427-solved-next-listing/#findComment-269164
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.