grant_p
07-30-2011, 04:29 PM
Hi guys,
Can anybody point me in the right direction on how to structure my query below, to check the REGION field in my database for one of two conditions
ie: The region field must contain any PHP region variable passed to it and find it, and it should also find all entries where the region value = national, and obviously the product and enabled fields need to match...
eg: REGION = 'DALLAS' OR REGION = 'NATIONAL' should return all entries containing the region stored as DALLAS as well as all entries containing a value of NATIONAL
I have tried with the following query without any luck:
$sql = "SELECT * FROM products WHERE REGION = '".$region."' OR REGION = 'NATIONAL' AND PRODUCT = 'Engine Block' AND ENABLED='1' order by PRODUCT_ID asc";
I am guessing that it is failing because of the combination of conditions OR and the AND's in the where clause... I am a beginner as far as MYSQL goes, and I have search high and low for a better way to structure this query where it actually does what I need, but couldn't find anything with my limited knowledge.
Any help will be greatly appreciated!
Thanks
Grant
Can anybody point me in the right direction on how to structure my query below, to check the REGION field in my database for one of two conditions
ie: The region field must contain any PHP region variable passed to it and find it, and it should also find all entries where the region value = national, and obviously the product and enabled fields need to match...
eg: REGION = 'DALLAS' OR REGION = 'NATIONAL' should return all entries containing the region stored as DALLAS as well as all entries containing a value of NATIONAL
I have tried with the following query without any luck:
$sql = "SELECT * FROM products WHERE REGION = '".$region."' OR REGION = 'NATIONAL' AND PRODUCT = 'Engine Block' AND ENABLED='1' order by PRODUCT_ID asc";
I am guessing that it is failing because of the combination of conditions OR and the AND's in the where clause... I am a beginner as far as MYSQL goes, and I have search high and low for a better way to structure this query where it actually does what I need, but couldn't find anything with my limited knowledge.
Any help will be greatly appreciated!
Thanks
Grant