How to mix to search queries to show results on the same page

BrighteyesDesign
BrighteyesDesign used Ask the Experts™
on
I have a page on a property page with two search functions. I want both searches to display results on the same page.

Search1 searches for a country Search2 search for county, city, bedrooms, min and max.


Search 2 works fine using:

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


mysql_select_db($database_Raglan, $Raglan);
$query_featured = sprintf("SELECT propertyID, bathrooms, bedrooms, mainimage, name, prices, pricePrefix, propertyType, regionCode, `currency`, country_code, cityCode FROM properties WHERE country_code = '$country_code'  AND cityCode = '$cityCode' AND bedrooms='$bedrooms' AND prices BETWEEN '$min' AND '$max' ORDER BY prices ASC", GetSQLValueString($colname_featured, "text"));

Open in new window


But search1 one does not work because it's only sending a country_code variable and because my query is looking for bedrooms and price nothing shows.

How can I have this so when a search is submitted with Search1 one all properties in the selected country display regardless of bedrooms and price?

I can send over bedrooms, city_code, min, max in the URL with a value of '0'  but i'm not sure how I would make it so '0' means show all results.


Hope this makes sense?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Your code only shows one query. Is there some missing?

If it was me, I would just run two queries and get two result sets and output them. I have included the general approach of what I would do and it is very simplified so that you get the general overview. None of it has been tested as it is illustrative rather than  a precise answer.

<?php

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


mysql_select_db($database_Raglan, $Raglan);

// search1
//
$search1 = sprintf("SELECT propertyID, bathrooms, bedrooms, mainimage, name, prices, pricePrefix, propertyType, regionCode, `currency`, country_code, cityCode FROM properties WHERE country_code = '$country_code' ORDER BY prices ASC", GetSQLValueString($colname_featured, "text"));

// search2
//
$search2 = sprintf("SELECT propertyID, bathrooms, bedrooms, mainimage, name, prices, pricePrefix, propertyType, regionCode, `currency`, country_code, cityCode FROM properties WHERE country_code = '$country_code'  AND cityCode = '$cityCode' AND bedrooms='$bedrooms' AND prices BETWEEN '$min' AND '$max' ORDER BY prices ASC", GetSQLValueString($colname_featured, "text"));


// Run the queries and build up a result string
//
$text1 = '';
$rs1 = mysql_query( $search1 );
if ( $rs1 )
     while ( $rw1 = mysql_fetch_assoc( $rs1 ) ) {

          // Format results into a text string. This is very simplified
          // as a demonstraton, but you could build a TABLE or a series
          // DIVs
          //
          $text1 .= "Name " . $rw1['name'] . " price " . $rw1['prices'];
     }


$text2 = '';
$rs2 = mysql_query( $search2 );
if ( $rs2 )
     while ( $rw2 = mysql_fetch_assoc( $rs1 ) ) {

          // Format results into a text string. This is very simplified
          // as a demonstraton, but you could build a TABLE or a series
          // DIVs
          //
          $text2 .= "Name " . $rw2['name'] . " price " . $rw2['prices'];
     }




// .... some else where you want these to display (presumably in HTML?)


       <div id='search1Results'>
          <?php echo $text1; ?>
       </div>
       ...
       ... more stuff
       ...
       <div id='search2Results'>
          <?php echo $text2; ?>
       </div>

Open in new window

I don't have a canned solution, but the general idea is to create a scoring system for relevance.  You might need to make multiple passes, or multiple queries, and score them , then combine them.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial