Or, a different approach:
PHP Code:
$IDs = array(-1);
foreach($data as $Key=>$Value){
$IDs[] = (int)$Value['SuperCatId'];
}
$IDsQueryPart = implode(', ', $IDs);
$sql = "Select Column1, Column2 FROM Table WHERE id IN({$IDsQueryPart})";
The initial -1 is there to stop the query having an empty IN(), which would throw an error. The bare minimum would be IN(-1), which should return nothing if no ID is -1. If that's a possibility, change -1 to an ID which can't be used.
Another approach, based on your current code, could be (though I'd rather the above...):
PHP Code:
$super_cats_id = '';
foreach($data as $k=>$v){
$super_cats_id .= ' OR id = ' . (int)$v['SuperCatId'];
}
$sql = "Select * FROM Table WHERE 1 = 0 {$super_cats_id}";
That will mean the query could be:
Code:
Select * FROM Table WHERE 1 = 0
(no results)
Code:
Select * FROM Table WHERE 1 = 0 OR id=1
(results)
Bookmarks