View Single Post
Old 11-28-2012, 01:51 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Have you heard of PRECEDENCE of operators?

If you took junior high school math, you should have.

For example, what is the value of
Code:
     3 + 4 * 2
??

If you said 14, then back to school for you!

Multiplication has a higher precedence than addition, so that expression is evaluate as if you had coded
Code:
    3 + ( 4 * 2 )
for an answer of 11.

If you WANTED the answer of 14, you should have written
Code:
    ( 3 + 4 ) * 2
***********

Guess what? SAME THING applies to LOGICAL operators. Yes, in SQL. And in PHP and in JavaScript and in every other standard computer language.

AND has a higher precedence than OR.
&& has a higher precedence than ||.
& has a higher precedence then |.

So... What you need is:
Code:
$sql = "
    SELECT * FROM hits 
    WHERE vc=1 AND country = 'us' 
    AND ( ua LIKE '%bot%' || ua LIKE '%spider%' || state NOT LIKE 'Florida')  
    ";

mysql_query( $sql )
Incidentally: Personally, I would use AND and OR in SQL, because ANSI SQL doesn't support && and || even if MySQL does. Be prepared for the day you may use some other DB than MySQL.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote