logical query is little tricky, it will check the condition sequentialy, for
example 'true OR false AND false' will return 'false'. here is the tracking:
first it will check 'true OR false', so the return is 'true'
then it will check 'true' AND 'false' and of course it will return false.
remember this :
1 AND 1 = 1
else is = 0
0 OR 0 = 0
else is 1
the problem is, you are not specify where statement executed first. you can
separate the statement with (), like 'true' OR ('false' AND 'false') will
return true.
i hope this explanation can clear you :)
oh and one thing, you can replace { had.breed = '1' or had.breed = '2' } with
{ had.breed BETWEEN '1' AND '2' }
and { had.breed != '18' and had.breed != '19' or had.breed != '20' } with {
had.breed NOT BETWEEN '18' AND '20' }
regards
marga A.K.A marsupilami_x
----- Original Message -----
From: Lenny Davila
To: [email protected]
Sent: Tuesday, September 04, 2007 4:16 AM
Subject: [php_mysql] Mysql and or statements
I have here a mysql statement
SELECT * FROM ad_ads ad left join horse_ads had on ad.ads_id = had.pid WHERE
ads_category = '1' and `ads_title` like '%Lenny%' or `ads_description` like
'%Lenny%' or had.breed = '1' or had.breed = '2' or had.breed != '18' and
had.breed != '19' or had.breed != '20' or had.breed != '-1'
It should not find where breed is equal to 19 , but it does. These are only
2 of the fields I have in my search criteria. Please let me know the
easiest way to get the statement working correctly.
Thanks
_.___
Recent Activity
a.. 8New Members
Visit Your Group
New web site?
Drive traffic now.
Get your business
on Yahoo! search.
Y! Messenger
Files to share?
Send up to 1GB of
files in an IM.
Yahoo! Groups
Endurance Zone
A Yahoo! Group
for better endurance.
.
[Non-text portions of this message have been removed]