Jump to content

Add More Where In Query


lovephp

Recommended Posts

or is this right, oh and the user is stored in session so i want it to display results according to users name

$results = mysql_query("SELECT * FROM table
WHERE (`user= ".$user."')
AND
(`phone` LIKE '%".$query."%')
OR
(`name` LIKE '%".$query."%')")
or
die(mysql_error());

You should use LIKE if you need LIKE. I was just showing the structure to use when you need an AND along with an OR. Since AND and OR have the same precedence, they are evaluated from left to right (or top to bottom). If you have: "Condition1 AND Condition2 OR Condition3" it evaluates differently than having: "Condition2 OR Condition3 AND Condition1". So you use the parenthesis to make sure the conditions are evaluated the way you want: "Condition1 AND (Condition2 OR Condition3)" (which is also evaluated differently from either of the other two).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.