dbk Posted June 19, 2010 Share Posted June 19, 2010 Hi guys I'm trying to make a mysql search function in my php page. The query looks like this and works fine: $search_contact_sql = "SELECT * FROM contact INNER JOIN project_contact USING (contact_id) WHERE (contact_title LIKE '%$search_contact%' OR contact_first_names LIKE '%$search_contact%' OR contact_surname LIKE '%$search_contact%' OR contact_company_relation LIKE '%$search_contact%' OR contact_company_section LIKE '%$search_contact%' OR contact_adress LIKE '%$search_contact%' OR contact_postal_number LIKE '%$search_contact%' OR contact_city LIKE '%$search_contact%' OR contact_phone LIKE '%$search_contact%' OR contact_fax LIKE '%$search_contact%' OR contact_cellphone LIKE '%$search_contact%' OR contact_private_phone LIKE '%$search_contact%' OR contact_mail LIKE '%$search_contact%' OR contact_notes LIKE '%$search_contact%') AND project_id != $project_id ORDER BY contact_title"; But... I want to exclude the result of this query in the search result: $search_contact_sql = "SELECT * FROM contact JOIN project_contact USING (contact_id) WHERE project_id = $project_id ORDER BY contact_title"; Is that somehow possible??? Quote Link to comment https://forums.phpfreaks.com/topic/205275-problems-with-complex-query/ Share on other sites More sharing options...
fenway Posted June 20, 2010 Share Posted June 20, 2010 You're missing parens. Quote Link to comment https://forums.phpfreaks.com/topic/205275-problems-with-complex-query/#findComment-1074488 Share on other sites More sharing options...
dbk Posted June 20, 2010 Author Share Posted June 20, 2010 Hi fenway I can't figure out where I'm missing parents? Is it to subtract one query from the other or.. is it in one of the queryes??? Each query gives the result I want, but I just want the 2. query result subtracted from the first query! I've been searching nearly all googles result to find a solution!! :'( Quote Link to comment https://forums.phpfreaks.com/topic/205275-problems-with-complex-query/#findComment-1074550 Share on other sites More sharing options...
fenway Posted June 20, 2010 Share Posted June 20, 2010 Not "parents", parens -- parentheses. You can't mix ANDs and ORs that way, since they have the same precedence -- you need to group all of the ORs together. Quote Link to comment https://forums.phpfreaks.com/topic/205275-problems-with-complex-query/#findComment-1074683 Share on other sites More sharing options...
dbk Posted June 21, 2010 Author Share Posted June 21, 2010 Thanks for the reply! I simply gave up on making the query I wanted! Instead I made a array to contain the one query I could use with the in_array function to check wich results from the other query I would make pass! Hope it made sens!! anyway.. it works!! Quote Link to comment https://forums.phpfreaks.com/topic/205275-problems-with-complex-query/#findComment-1075129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.