Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Show selected search value in dropdown

Posted on 2012-08-11
6
Medium Priority
?
484 Views
Last Modified: 2012-08-11
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
0
Comment
Question by:BrighteyesDesign
  • 2
  • 2
  • 2
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38283513
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
 

Author Comment

by:BrighteyesDesign
ID: 38283544
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
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 38283550
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38283558
OK, I selected it.  What should I be seeing that I am not seeing?
0
 

Author Comment

by:BrighteyesDesign
ID: 38283602
Julian explained it better than me Ray!

Thanks for that Julian all is working great.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38283651
you are welcome
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question