0

Hi
I'm trying to write a query which when 0 is selected it brings back all the district_zones otherwise it just brings back the selected zone.

It brings back the selected zone fine, but not all records which are not 0

I know it is my wildcard that is the problem - but I dont'know what to use.

Any help would be great.

Many thanks

if ($_POST[district_zone] == "0") { $receivezone = "%"; } else {$receivezone = $_POST[district_zone];} 
$query_rs_district = "SELECT property_districts.district_zone, property_districts.district_name FROM property_districts WHERE property_districts.district_zone = '$receivezone' ";
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ebanbury
0

MySQL wildcard comparison needs the "like" operator:

if ($_POST[district_zone] == "0") { $receivezone = "like '%'"; } else {$receivezone = "= " . $_POST[district_zone];} 
$query_rs_district = "SELECT property_districts.district_zone, property_districts.district_name FROM property_districts WHERE property_districts.district_zone '$receivezone' ";
0

Hi Great thanks for getting back to me.

I also 'discovered' that the word LIKE works in the SELECT part of the query....

So I did this:

if ($_POST[district_zone] == "All") { $lcl_district_zone = "%"; } else { $lcl_district_zone = $_POST[district_zone]; } 

 { $query_rs_search = "SELECT property_districts.district_name FROM  property_districts
WHERE property_districts.district_zone LIKE '$lcl_district_zone'
0

So sorry yes your right...LIKE is the key word.

Many thanks for the help. Much appreciated.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.