Hi everybody !
I have a question for the gurus ;+)
I have to arrays :
$id = array(45,9,21);
$pos = array(3,1,2);
I select in my mysql table using the ids :
$sql = "SELECT * FROM MyTable WHERE id IN(".implode("",$id).")";
and I now want to sort the result according to the $pos array.
Is there a way to do this directly in mysql ?
If not, what would be the smartest way to do it in PHP ?
Because I would prefer NOT to do the following :
while ($t = mysql_fetch_array($ret)) {
$a_field1[] = $t["field1"];
$a_field2[] = $t["field2"];
$a_field3[] = $t["field3"];
$a_field4[] = $t["field4"];
...
}
array_multisort($pos,$a_field1,$a_field2,$a_field3,$a_field4)
I fear it could be a very time consuming process when there is a lot of results and a lot of fields. But may be the no other solution...
Thanks