1.(standard)
foreach($images as $k=>$v)
{
//each image we do an update query
$q="update `images` SET `orderby`=".$v." WHERE `idimage`=".$k;
//execute $q
}
2. (more interesting)
$q="UPDATE `images` SET `orderby`= CASE `idimage` ";
$ids=implode(',',array_keys($images));
foreach($image as $k=>$v){
$q.=' WHEN '.$k.' THEN '.$v;
}
$q.=' END WHERE `idimage` IN('.$ids.')';
//execute $q
So which do you think is better?when i try to do explain in the second case i get an error, that the query has an error.
Not quite sure, but i think that the second case is better , so i decided to ask the mysql gurus

New Topic/Question
Reply



MultiQuote





|