shackwm60 Posted January 10, 2015 Share Posted January 10, 2015 This will be an easy one for you guys... One of the fields in a MySQL database is a varchar() that was populated using a checkbox method and can contain more than one response. in this case i have blue, yellow, green and want to check if the field contains blue before echoing the statement to the screen. How would i use strpos in this case? ive tried a few thigns and get syntax error. The below of course works if the field ONLY contains blue. if (($row['colorsyoulike']) =='blue') { echo "<tr>"; echo "<td>Blue is an available Color!</td>"; } thanks. Quote Link to comment Share on other sites More sharing options...
Solution CroNiX Posted January 10, 2015 Solution Share Posted January 10, 2015 if (strpos($row['colorsyoulike'], 'blue') !== FALSE) { //$row['colorsyoulike'] contained 'blue' somewhere in the string } strpos() will return boolean FALSE if the string isn't contained in the search string. However, it would probably be better to use stripos() which is case-insensitive, so it will match blue, BLUE, Blue, BlUe etc. 1 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 10, 2015 Share Posted January 10, 2015 or you could just normalize the data, storing each value in its own row in a database table and let the database do all the work when inserting, finding, or deleting any of data without needing a bunch of php code. Quote Link to comment Share on other sites More sharing options...
shackwm60 Posted January 10, 2015 Author Share Posted January 10, 2015 Thanks Cronix.. that did it. I was way off. Unfortunately mac-gyver the db has existed for a while and theeres numerous instances like this one. i am just making changes for someone. thanks for the input. 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.