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' ";

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' ";

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'

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

Many thanks for the help. Much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.