You may explode your session value to array:
$locs = explode(', ' $_SESSION['locs']);
And SQL was follow:
$where = "WHERE ";
$count = count($locs);
for ($i = 0; $i < $count; $i++) {
$where .= "location LIKE '%, ". $locs[$i] .",%' ";
$where .= " OR location LIKE '%, ". $locs[$i] ."%' ";
if ($i < $count - 1) {
$where .= " OR ";
}
}
Or use MySQL RegEx for regular expression search
Better way is to use REGEXP:
$where = "WHERE ";
$count = count($locs);
for ($i = 0; $i < $count; $i++) {
$where .= "location REGEXP '(,[[:blank:]]*|^)". $locs[$i] ."(,|$)'";
if ($i < $count - 1) {
$where .= " OR ";
}
}
I tested them, it's work on "1, 2, 3"
string for any number.