Why doesnt this mySql query work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Why doesnt this mySql query work?

Post by dominod »

Hi,

I cant get this MySql query to work:

Code: Select all

$query = "SELECT * FROM `engines` WHERE name LIKE '$keyword%' AND languages='au' OR language='en' ORDER BY hits DESC ";
It is the AND languages='au' OR language='en' part which I cant get to work I think.. I want it to select it IF language is either 'en' OR 'au'...

Thanks in advnace :)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Why doesnt this mySql query work?

Post by Jonah Bron »

Code: Select all

$query = "SELECT * FROM `engines` WHERE name LIKE '$keyword%' AND (languages='au' OR language='en') ORDER BY hits DESC ";
Should work. Specify logic hierarchy with parentheses.
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Why doesnt this mySql query work?

Post by dominod »

Thanks alot! :)
Post Reply