Not sure if i labeled this question clearly, however, i have a MySQL table with a column zones
. This column holds the values of a checkbox array that has been run through PHP's implode like so:
if(isset($_POST['checkbox'])) {
$zones = implode(',', $_POST['checkbox']);
}
This saves the data in a string format like 2,3,4,5
.
I'd like to create a query to basically match any number in that individual column. So far my query looks like:
$zoneId = '2';
SELECT * FROM $alert_table WHERE `zones` LIKE $zoneId AND `time_created` < DATE_SUB(NOW(), INTERVAL 2 HOUR) ORDER BY `id` ASC LIMIT 1;
It works perfectly if the column only has 1 number. But fails if the column has the string 2,3,4,5
.
Any help is appreciated, i am not opposed to a change in method of storing the checkbox values if their is a better alternative.