wkilc Posted August 16, 2010 Share Posted August 16, 2010 Hi all, I am placing First and Last names together as $name; and Phone and E-mails together, as $contact. $query = "SELECT user.Member,user.First,user.Last,user.Phone,user.Email,user.Type FROM user WHERE ((user.MemberNo LIKE '$MemberNo%') and (user.First LIKE '%$name%') or (user.Last LIKE '%$name%') and (user.Phone LIKE '$contact%') and (user.Email LIKE '$contact%') and (user.Type LIKE '$Type%')) ORDER BY user_stuff.$sort LIMIT $eu, $limit "; $result = mysql_query($query); I use the OR becasue I want to be able to search the "whole" name, first and last. When I run a URL query, it works for name, but everything else (Type, contact, Member)won't filter by URL. If I remove the OR and replace it with AND, everything else works again. Is this something that happens after using OR? (Except for name) Help please? Do I need to separate the query? ~Wayne Link to comment https://forums.phpfreaks.com/topic/210903-and-and-or-in-query/ Share on other sites More sharing options...
schilly Posted August 16, 2010 Share Posted August 16, 2010 $query = "SELECT user.Member,user.First,user.Last,user.Phone,user.Email,user.Type FROM user WHERE ((user.MemberNo LIKE '$MemberNo%') and ((user.First LIKE '%$name%') or (user.Last LIKE '%$name%')) and (user.Phone LIKE '$contact%') and (user.Email LIKE '$contact%') and (user.Type LIKE '$Type%')) ORDER BY user_stuff.$sort LIMIT $eu, $limit "; You need to bracket your OR statement together. Right now it is being evaluated as (MemberNo and First) OR (last and phone and email and type) Link to comment https://forums.phpfreaks.com/topic/210903-and-and-or-in-query/#findComment-1100029 Share on other sites More sharing options...
wkilc Posted August 17, 2010 Author Share Posted August 17, 2010 THANK YOU! What would an idiot like me do without this forum? ~Wayne Link to comment https://forums.phpfreaks.com/topic/210903-and-and-or-in-query/#findComment-1100030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.