Reputation: 17
I have a array i.e.
$frame = Array(
[0]=1,
[1]=2,
[2]=4
);
and I want to get value form table "standard_product" where "frame_category" is a column name, this column value are look like
frame_category
4,7
1,3,4
6,7,8
return all row if any value of $frame match with any value of frame_category column. Here require result is:
4,7
1,3,4
My effort to resolve this is:
Standard_product::Where('frame_category', 'LIKE', '%' . $frame . '%')->get()->toArray();
(SELECT * FROM `standard_products` WHERE `frame_category` LIKE "%".$frame."%");
but i will not return expected result. Please help me.
Upvotes: 0
Views: 1652
Reputation: 685
$frame = Array( [0]=1, [1]=2,[0]=4 );
foreach ($frame as $val) {
$query = mysql_query("SELECT * FROM `standard_products` WHERE find_in_set(".$val.", frame_category)");
while($row = mysql_fetch_assoc($query)){
$result[] = $row;
}
}
Upvotes: 1
Reputation: 38642
remove toArray()
last in the query
Standard_product::where('frame_category', 'LIKE', '%'.$frame.'%')->get();
or
Standard_product::like('frame_category', '%$frame%')->get();
Or
$category = DB::table('Standard_product')
->where('frame_category', 'like', '%$frame%')
->get();
Upvotes: 1
Reputation: 6661
use MySQL IN
$ids = join(',', $frame);
WHERE frame_category IN ($ids)
Passing Your to array to MySQL like that
Upvotes: 1