I want to search some products and get results . This is my PHP code:
function Item_Search($AppID, $Keyword = '', $Wears)
{
// expected $Wears = [1,0,1,0,1] , numbers can be diffrent from 0 to 1
$WearNames = ['red', 'green', 'blue', 'yellow', 'black'];
$FinalWear = [];
foreach ($Wears as $i => $Wear) {
if ($Wear == 1) {
$FinalWear[] = $WearNames[$i];
}
}
$FinalWear = json_encode($FinalWear);
$FinalWear = str_replace(str_split('[]'), '', $FinalWear);
$ItemList = Query("SELECT * FROM items WHERE appid=$AppID
AND name LIKE '%$Keyword%'
AND wear IN ($FinalWear)
");
}
This code works just fine, but there are some products without any color . In this case I want to say if all colors were 1 (true), then show products without color too.
So my question is, can I put something as $FinalWear
in wear IN ($FinalWear)
so I can get all the results?