mysql order by issue

前端 未结 5 1055
后悔当初
后悔当初 2021-01-06 09:57

if i have a query like :

SELECT * FROM table  WHERE id IN (3,6,1,8,9);

this array of the ids is build in php dynamically , and the order is

5条回答
  •  既然无缘
    2021-01-06 10:21

    You can load the results into an array with IDs as indexes:

     while ($row = mysql_fetch_array($l)) $items[$row['id']] = $row;
    

    and then simply iterate it in your order

     foreach ($my_array as $id) { $current_row = $items[$id]; ... }
    

提交回复
热议问题