Jump to content

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());

Edited by lovephp

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.