springmedia Posted June 5, 2011 Share Posted June 5, 2011 Hi there people, just wondering if you could help me out I am having a problem with creating my select statement. $term = $_POST['term']; $sql2 = mysql_query("SELECT * FROM members WHERE '$term%' IN(location1,location2,location3,location4,location5)"); basically I am after a search from form post $term to return all matching values from the columns "location1" through to location5. I am not sure if I am going the right way about this but any help would be appreciated. Kind Regards, Rich Quote Link to comment https://forums.phpfreaks.com/topic/238468-mysql-select-query/ Share on other sites More sharing options...
requinix Posted June 5, 2011 Share Posted June 5, 2011 Is this a kind of search? IN only does exact searches - you need LIKE. WHERE location1 LIKE "$term%" OR location2 LIKE "$term%"... Separate issue: why do you have six locationN columns? Is there a chance you might need seven? Quote Link to comment https://forums.phpfreaks.com/topic/238468-mysql-select-query/#findComment-1225414 Share on other sites More sharing options...
springmedia Posted June 5, 2011 Author Share Posted June 5, 2011 Thank you requinix, I can't believe I didn't see that. Guess I have been looking at this code for too long. The main reason is for a business profile search. 1 business profile can appear in multiple locations around the country if assigned a location prefix. Saves making multiple profiles for the business. Thanks again, Kind regards, Rich Quote Link to comment https://forums.phpfreaks.com/topic/238468-mysql-select-query/#findComment-1225418 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.