I have both side coma separated values like
$ing=1,2,3,4,5,6
and the database has a table with values
IDS 5,2,1,6,2,3,45 // in database
I know this is not a good practice but I had to do this to get the values in one query. i also have a separate table where the IDS are separate and corresponds to separate users like
user 1 IDS 2
user 3 IDS 65 etc
As of now I am using
$conditions[] = "CONCAT(',', `rcring`, ',') REGEXP ',($ing),'";
It gives me good results but it gives me the values in which either of the $ing exists i want only the tables which has atleast all the $ing
Can you help me please I tried my work and I cant get a proper solution anywhere . thankx .
//EDIT
i already have condition as an array
if($ser !=''){
$conditions[] = "rc_ser='$ser'";
}if($fridge == 1){
$ing="0|";
$ctch2fr='checked';
foreach($_SESSION['fridge'] as $item){
$ing=$ing.$item."|";}
$conditions[] = "CONCAT(',', `rcring`, ',') REGEXP ',($ing),'";
}
if (count($conditions) > 0) {
$sql= implode(' AND ', $conditions);
}
Like this as an condition in array and i am calling it like this in query
select * ,(select count(rcid) from recipe where ($sql)) as total from recipe where ($sql)
i tried the answers below bu it gives me 0 result always when i print the query it shows me like this
select *,(select count(rcid) from recipe where (CONCAT(',', `rcring`, ',') REGEXP ',(0),') ) as total from recipe where (CONCAT(',', `rcring`, ',') REGEXP ',(0),')