tmh766 Posted April 5, 2009 Share Posted April 5, 2009 Hey I can't seem to figure out how to write this query. I have a PHP variable set to, for example: $match='a,b,c'; and want to check if a MySql field's value is within the variable match, not the other way around like usual. So if theMySql field had a value of "a", that row would be returned because the field's value is a substring of the variable match. Tim Quote Link to comment Share on other sites More sharing options...
corbin Posted April 5, 2009 Share Posted April 5, 2009 You could use IN. Except for your string would need to be formatted differently. Example query: SELECT * FROM table1 WHERE field1 IN('a', 'b', 'c'); So, if you had a comma separated list in PHP, you could do something like this: "SELECT * FROM table1 WHERE field1 IN ('" . implode("', '", explode(",", $input)) . "');" Edit: By the way, it would be wiser to explode() the array and then mysql_real_escape_string all of the pieces before putting it back together. Quote Link to comment Share on other sites More sharing options...
tmh766 Posted April 5, 2009 Author Share Posted April 5, 2009 Hey Thank you so much, I didn't know about that. Quote Link to comment Share on other sites More sharing options...
corbin Posted April 5, 2009 Share Posted April 5, 2009 ;p Quote Link to comment 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.