zero_ZX Posted August 17, 2010 Share Posted August 17, 2010 Hello, I have a query where i try to search, but i want to put a limitation, but it doesn't seems to be working :/ Here's my code: $result = mysql_query("SELECT * FROM clients WHERE staff = 0 AND username LIKE '%" . $keyword . "%' OR company LIKE '%" . $keyword . "%' ORcontact LIKE '%" . $keyword . "%' OR address LIKE '%" . $keyword . "%' OR email LIKE '%" . $keyword . "%' OR phone LIKE '%" . $keyword . "%' ORDER BY phone"); Alright, so i basically want the user to search in all of those fields, however i want it to filter all "staff" members, so it should only view the "0" ones, meaning the clients, only problem that when i run this, all clients gets displayed, also the staff accounts. Any suggestion? Link to comment https://forums.phpfreaks.com/topic/210969-mysql-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2010 Share Posted August 17, 2010 If you want a specific value AND any of the other values, you must () to indicate that's what you want - "SELECT * FROM clients WHERE staff = 0 AND (username LIKE '%" . $keyword . "%' OR company LIKE '%" . $keyword . "%' OR contact LIKE '%" . $keyword . "%' OR address LIKE '%" . $keyword . "%' OR email LIKE '%" . $keyword . "%' OR phone LIKE '%" . $keyword . "%' ORDER BY phone)" Link to comment https://forums.phpfreaks.com/topic/210969-mysql-query/#findComment-1100374 Share on other sites More sharing options...
zero_ZX Posted August 17, 2010 Author Share Posted August 17, 2010 Oh ya that's right, thanks a lot! Remember that order by shouldn't be, so the final code would be "SELECT * FROM clients WHERE staff = 0 AND (username LIKE '%" . $keyword . "%' OR company LIKE '%" . $keyword . "%' OR contact LIKE '%" . $keyword . "%' OR address LIKE '%" . $keyword . "%' OR email LIKE '%" . $keyword . "%' OR phone LIKE '%" . $keyword . "%') ORDER BY phone" Link to comment https://forums.phpfreaks.com/topic/210969-mysql-query/#findComment-1100382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.