Link to home
Start Free TrialLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

asked on

Show selected search value in dropdown

For a real estate site I have a search facility which is almost there.

I need to create a function so when a user makes a search for an area that area shows as default on the results page (which is the same page).

If you go to this link http://95.128.128.74/~raglanin/uksearchlet.php?saleOrRent=rent&intsearch=GBR&min=0&max=10000000&bedrooms

Then select a London area in the 'refine search' section you'll see what I mean.  If for instance you select 'London, Chelsea' you will see results for that area but the dropdown then defaults to 'Any' so if you further refine the search your actually searching all of London rather that the specific suburb ie Chelsea.

Here's the code I use for the dropdown..
   <select name="city" id="city" >
         <option value="" selected>Any</option>
      
          <?php
do {  
?>
          <option value="<?php echo $row_cities['ID']?>"<?php if (!(strcmp($row_cities['ID'], $row_cities['Code'])))  ?>><?php echo $row_cities['Name']?></option>
          <?php
} while ($row_cities = mysql_fetch_assoc($cities));
  $rows = mysql_num_rows($cities);
  if($rows > 0) {
      mysql_data_seek($cities, 0);
	  $row_cities = mysql_fetch_assoc($cities);
  }
?>
        </select>

Open in new window



And this is the queries used on the page (not all may be applicable to this problem though)

$country_code = $_GET["intsearch"];
$bedrooms = $_GET["bedrooms"];
$min = $_GET["min"];
$max = $_GET["max"];
$cityCode = $_GET["city"];
$saleOrRent = $_GET["saleOrRent"];



mysql_select_db($database_Raglan, $Raglan);
$query_cities = "SELECT DISTINCT City.Name,City.ID FROM properties LEFT JOIN City ON City.ID = cityCode WHERE country_code = 'GBR' AND saleOrRent ='rent'";

$cities = mysql_query($query_cities, $Raglan) or die(mysql_error());
$row_cities = mysql_fetch_assoc($cities);
$totalRows_cities = mysql_num_rows($cities);


mysql_select_db($database_Raglan, $Raglan);
$query_countries = 'SELECT DISTINCT Country.Name,Country.Code FROM properties LEFT JOIN Country ON Country.Code = properties.country_code ORDER by Name ASC';

$countries = mysql_query($query_countries, $Raglan) or die(mysql_error());
$row_countries = mysql_fetch_assoc($countries);
$totalRows_countries = mysql_num_rows($countries);



$colname_info = "-1";
if (isset($_GET['intsearch'])) {
  $colname_info = $_GET['intsearch'];
}
mysql_select_db($database_Raglan, $Raglan);
$query_info = sprintf("SELECT * FROM Country WHERE Code = %s", GetSQLValueString($colname_info, "text"));
$info = mysql_query($query_info, $Raglan) or die(mysql_error());
$row_info = mysql_fetch_assoc($info);
$totalRows_info = mysql_num_rows($info);




$maxRows_featured = 16;
$pageNum_featured = 0;
if (isset($_GET['pageNum_featured'])) {
  $pageNum_featured = $_GET['pageNum_featured'];
}
$startRow_featured = $pageNum_featured * $maxRows_featured;

$query_featured = "SELECT properties.propertyID, properties.live, properties.pricePrefix, properties.country_code, properties.saleOrRent, images.filename, properties.name, FORMAT(properties.prices,0) as prices, properties.currency FROM properties INNER JOIN images ON properties.propertyID=images.propertyid WHERE properties.country_code = '$country_code' AND properties.live = '1'
AND images.selected = '1'
      AND (properties.cityCode = '$cityCode' or '$cityCode' = '')
       AND (properties.saleOrRent = '$saleOrRent' or '$saleOrRent' = '') ";

if ($bedrooms!="10"){
 $query_featured.= "AND (properties.bedrooms='$bedrooms' or '$bedrooms' = '')";
}
else
{
 $query_featured.= "AND (properties.bedrooms>=10)";
}

$query_featured .=" AND ( (properties.prices BETWEEN '$min' AND '$max' ) OR properties.prices is null ) ORDER BY properties.prices ASC";
 
 
 
 
 
$query_limit_featured = sprintf("%s LIMIT %d, %d", $query_featured, $startRow_featured, $maxRows_featured);
$featured = mysql_query($query_limit_featured, $Raglan) or die(mysql_error());
$row_featured = mysql_fetch_assoc($featured);

if (isset($_GET['totalRows_featured'])) {
  $totalRows_featured = $_GET['totalRows_featured'];
} else {
  $all_featured = mysql_query($query_featured);
  $totalRows_featured = mysql_num_rows($all_featured);
}
$totalPages_featured = ceil($totalRows_featured/$maxRows_featured)-1;

if ($HLoop_featured_rows < 1){
	$HLoop_featured_rows = ceil($totalRows_featured / $HLoop_featured_columns);
	if($HLoop_featured_loopTo < 1) {
		$HLoop_featured_loopTo = $HLoop_featured_rows;
	}
} 

$queryString_featured = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_featured") == false && 
        stristr($param, "totalRows_featured") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_featured = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_featured = sprintf("&totalRows_featured=%d%s", $totalRows_featured, $queryString_featured);




?>

Open in new window



Hope you can help! If you need any more info fire away
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Can you please clarify the question?  I went to the page and selected Portugal, but it gave me a list of London neighborhoods when I tried to refine the search.  While I'm fairly sure that's not what we want, I'm not clear on the issue.
Avatar of BrighteyesDesign

ASKER

Hi Ray,

I see what you're saying, i'll make the process clearer graphically.

The international search is separate so ignore that. You can basically search either International or UK properties. Just select from the 'UK search' row (which was 'refine search before'.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, I selected it.  What should I be seeing that I am not seeing?
Julian explained it better than me Ray!

Thanks for that Julian all is working great.
you are welcome