View Single Post
  #1  
Old 23rd December 2009, 15:12
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,044
Thanks: 269
Thanked 154 Times in 133 Posts
Default Help: MySQL WHERE OR AND

Some one here who can explain why this query is working fine:

Code:
$findThis = "testing";
$inCategory = "cat1";

SELECT * 
FROM 				products 
WHERE				products.Desc LIKE '%$findThis%'
AND 				category= '$inCategory";
It returns the correct info, from cat1.

But when I want to search in more product fields (in this case also the Title), and when I set the inCategory to an other value it still shows the info from cat1

Code:
$findThis = "testing";
$inCategory = "cat2";

SELECT * 
FROM 				products 
WHERE				products.Desc LIKE '%$findThis%'
OR				products.Title LIKE '%$findThis%'
AND 				category= '$inCategory";
I have also tested this:

Code:
SELECT * 
FROM 				products 
WHERE				products.Desc LIKE '%$findThis%' || products.Title LIKE '%$findThis%'
AND 				category= '$inCategory";
But I get the same results as the 2nd query.

For some reason the AND does not work correct!

Anyone here who can show me what the correct syntax is?
Reply With Quote
Sponsored Links