Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

am having problem with my search mysql script, pls help

Featured Replies

Hello pls am having problem with my script and its like this.

I am developing a property site where visitors can search for property. I have 5 dropdowns in the search script, eg as below:

 

STATE (dropdown)

All

New York

Los Angeles

Ohio

 

CITY (dropdown)

All

(the remaining list of cities here will be determined by the state selected above)

 

Type (dropdown)

Sales

Buy

 

MIN PRICE (dropdown)

All

$500

$2,000

$10,000

$500,000

 

MAX PRICE (dropdown)

All

$500

$2,000

$10,000

$500,000

 

If the visitor selected all in all the 4 fields (exept type field), I search my table as below;

 

$search="select * from property where type='$type'";

$query=mysql_query($search)

 

The above worked fine, but how will i put teh script when some are 'ALL' and some are not 'ALL'

 

I tried the below but it didn't word

 

if($state=='All') {$state2="";} else {$state2="state='$state' ";}

if(($state=="All") && ($city != "All")) {$city2= "city = '$city' ";}
elseif(($state!="All") && ($city != "All")) {$city2= "and city = '$city' ";}
else $city2="";

if(($state=="All") && (city == "All")) {$type2 .= "type = '$type' ";}
else {$type2= "and type = '$type' ";}

if($property=='All') $property2=""; else $property2="and property = '$property' ";

if($min_price=='All') $min_price2=""; else $min_price2="and min_price => '$min_price' ";

if($max_price=='All') $max_price2=""; else $max_price2="and max_price <= '$max_price' ";

$where = $state2."".$city2."".$type2."".$property2."".$min_price."".$max_price;

$select="select * from property where $where order by property_id desc";
$query = mysql_query($sql_select);

I also use this

 

$type2 = "type='$type' and ";
if($state=='All') {$state2==""; $city2=="";}
elseif($state!='All' && $city=="All") $state2=" state='$state' and";
else $state2=" state='$state' and city='$city' and ";

if($property=='All') $property2=="";
elseif($property=='All' && $min_price!='All') $property2=="property='$property' and ";
else $property2="property='$property'";


if($min_price=='All') $min_price2=="";
elseif($min_price=='All' && $max_price!="All") $min_price2=="min_price='$min_price' and ";
else $min_price2="min_price='$min_price'";


if($max_price=='All') $max_price2=="";
elseif($max_price=='All' && $bedroom!='any') $max_price2=="max_price='$max_price' and ";
else $max_price2="max_price='$max_price'";


if($bedroom=='any') $bedroom2=="";
elseif($bedroom!='any') $bedroom2=="bedroom='$bedroom' and ";
else $bedroom2="bedroom='$bedroom'";


if($bathroom=='any') $bathroom2=="";
else $bathroom2=" and bathroom='$bathroom'";

$where = "where ";
$where .= $state2;
$where .= $city2;
$where .= $min_price2;
$where .= $type2;
$where .= $property2;
$where .= $max_price2;
$where .= $bedroom;
$where .= $bathroom;

$sql_select="select * from property $where order by property_id desc LIMIT $from,$max_results";
$query = mysql_query($sql_select);

 

Pls what can I do?

Do you get any errors? You assign your query string to $select but use $sql_select in your mysql_query() call.

 

What does your SQL statement look like when you echo it? You use $min_price and $max_price to construct $where but from your code it looks like you should be using $min_price2 and $max_price2.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.