inspireddesign Posted July 29, 2009 Share Posted July 29, 2009 Hello there, For whatever reason my query is displaying the same result over-&-over again in the loop. It's not a continues loop. It acts like there are several of the same entries in the database when there is only one entry. What might be causing this? I would think it has to do with the JOIN method I'm using but not sure? Thanks for any help on this. Let me know if you need more information (code). <?php $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. $searchSQL = "SELECT * FROM contacts "; $searchSQL .= "LEFT JOIN policies ON (policies.policy_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN aircraft ON (aircraft.aircraft_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN airport ON (airport.airport_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN product ON (product.product_contact = contacts.contact_id) "; $searchSQL .= "WHERE policies.policy_num LIKE '%{$searchTermDB}%' "; $searchSQL .= "OR aircraft.aircraft_n LIKE '%{$searchTermDB}%' "; $searchSQL .= "OR contacts.contact_primary LIKE '%{$searchTermDB}%' OR contacts.contact_zip LIKE '%{$searchTermDB}%' "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/167984-solved-query-help-making-me-nuts/ Share on other sites More sharing options...
onedumbcoder Posted July 29, 2009 Share Posted July 29, 2009 try distinct $searchSQL = "SELECT DISTINCT * FROM contacts "; $searchSQL .= "LEFT JOIN policies ON (policies.policy_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN aircraft ON (aircraft.aircraft_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN airport ON (airport.airport_contact = contacts.contact_id) "; $searchSQL .= "LEFT JOIN product ON (product.product_contact = contacts.contact_id) "; $searchSQL .= "WHERE policies.policy_num LIKE '%{$searchTermDB}%' "; $searchSQL .= "OR aircraft.aircraft_n LIKE '%{$searchTermDB}%' "; $searchSQL .= "OR contacts.contact_primary LIKE '%{$searchTermDB}%' OR contacts.contact_zip LIKE '%{$searchTermDB}%' "; Without it, your query should return the same results multiple times if I understand it right. This is due to your OR statements. Quote Link to comment https://forums.phpfreaks.com/topic/167984-solved-query-help-making-me-nuts/#findComment-886013 Share on other sites More sharing options...
inspireddesign Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks! that helped. I also defined what columns to select. This also made some differences in the results. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/167984-solved-query-help-making-me-nuts/#findComment-886069 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.