Faloude Faloude - 18 days ago 7
SQL Question

SilverStipe get by id in exact order

Suppose you have an array of keys

$key_list = array(3, 6, 2);

And you want to retrieve records from a certain table, using these keys as identifiers (WHERE ID = id_from_key_list)


This returns the rows with the ID's that match those in
(3, 6 and 2) but not in that order.

How to maintain the same order?


What you might need to do is to run a foreah loop of the IDs and push each Foo Object into an ArrayList

$aFooList = ArrayList::create(); 
foreach ($key_list as $key_list_id){
   $oFoo = Foo::get()->byID($key_list_id);
return $oFoo;