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
BrighteyesDesignAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
If I understand you correctly what you want is when you you search on a particular area you want that area to be shown in the dropdown on the results page

I changed your coding for the select because the version you have does not make sense

<select name="city" id="city" >
  <option value="" selected>Any</option>
<?php
// get the current value from the dropdown
// You may already have grabbed this value elsewhere in which case
// change to the variable you are using

$current=htmlentities($_GET['name']);

while ($row_cities = mysql_fetch_assoc($cities)) :

  // Check the value of the name field - if it is the same as the one 
  // currently being dealt with in the loop set the option to selected 

  $selected = ($current == $row_cities['ID'])?'selected="selected"':'';

  // Add the selected string to the option - it will be blank unless this is the same
  // option the user selected.
?>
  <option value="<?php echo $row_cities['ID']?>"<?php echo $selected?>><?php echo $row_cities['Name']?></option>
<?php endwhile;?>
</select>

Open in new window

0
 
Ray PaseurCommented:
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.
0
 
BrighteyesDesignAuthor Commented:
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'.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
OK, I selected it.  What should I be seeing that I am not seeing?
0
 
BrighteyesDesignAuthor Commented:
Julian explained it better than me Ray!

Thanks for that Julian all is working great.
0
 
Julian HansenCommented:
you are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.