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. Link to comment https://forums.phpfreaks.com/topic/293813-strpos-quesiton/ Share on other sites More sharing options...
CroNiX Posted January 10, 2015 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. Link to comment https://forums.phpfreaks.com/topic/293813-strpos-quesiton/#findComment-1502426 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. Link to comment https://forums.phpfreaks.com/topic/293813-strpos-quesiton/#findComment-1502427 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. Link to comment https://forums.phpfreaks.com/topic/293813-strpos-quesiton/#findComment-1502428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.