I have a php form with one of the fields being a dropdown box that allows multi select, this field is set as a varchar and points to another table for its options, the options are 1 to 8.
I would like to run an if code after adding a record, i can do this if the value is a single value, ie if($value==1), but as this dropdown allows multi select, it is possible for the field to save as 1,2,4,6 or 2,3,4, i.e. any combination of 1 to 8, and separated by a comma.
So what I need to do is get something like if($value….contains 1) {then do something }
Any ideas please
2
Answers
You can use explode method
Then you can use foreach loop
Example code will look like
the problem with string_contains is that if value contains a number 15, it would true the condition as it does contain 1 in 15…