jesushax Posted March 30, 2009 Share Posted March 30, 2009 hi all what im tryign to do is, find a value in a field to return results by eg mysql_query("SELECT 8 * FROM tblDirectory WHERE Sect1_2='Has the value Architects inside it'") or die(mysql_error()); the field Sect1_2 has values delimited by commas "Architects, Builders, Joiners, Plumbers," so i would like to be able to return all results that have the word Architects in how would i do that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/151728-solved-mysql-query-find-value-in-a-field/ Share on other sites More sharing options...
Mark Baker Posted March 30, 2009 Share Posted March 30, 2009 mysql_query("SELECT 8 * FROM tblDirectory WHERE Sect1_2 LIKE'%Architects%'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/151728-solved-mysql-query-find-value-in-a-field/#findComment-796737 Share on other sites More sharing options...
jesushax Posted March 30, 2009 Author Share Posted March 30, 2009 but will LIKE get them if the word Architects is anywhere in the field not just at the begining? thanks Quote Link to comment https://forums.phpfreaks.com/topic/151728-solved-mysql-query-find-value-in-a-field/#findComment-796744 Share on other sites More sharing options...
Mark Baker Posted March 30, 2009 Share Posted March 30, 2009 It's all down to the % sign: LIKE'%Architects%' will match if the word 'Architects' appears anywhere in the field LIKE'Architects%' will match if the word 'Architects' appears at the very beginning of the field LIKE'%Architects' will match if the word 'Architects' appears at the very end of the field Quote Link to comment https://forums.phpfreaks.com/topic/151728-solved-mysql-query-find-value-in-a-field/#findComment-796746 Share on other sites More sharing options...
jesushax Posted March 30, 2009 Author Share Posted March 30, 2009 gotcha, thank alot Quote Link to comment https://forums.phpfreaks.com/topic/151728-solved-mysql-query-find-value-in-a-field/#findComment-796747 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.