Skip to main content
added 18 characters in body
Source Link
goat
  • 31.8k
  • 7
  • 75
  • 96

I'm not familiar with cake or its database layers, but maybe you can add a little bit of sql.

The relevant sql would be something like

order by field(myTable.myID, 35, 15, 25)
-- or alternatively, more cross database compatible
order by case when myTable.myID = 35 then 1
              when myTable.myID = 15 then 2
              when myTable.myID = 25 then 3
         end

however, the most universal approach would be to just reorder in php code.

$products = array(35,15,25);//the ordered array
$records = array_flip($products);
foreach ($list as $row) {
    $id = $row['Product']['id'];
    $records[$id] = $row;
}
print_r($records);

I'm not familiar with cake or its database layers, but maybe you can add a little bit of sql.

The relevant sql would be something like

order by field(myTable.myID, 35, 15, 25)
-- or alternatively, more cross database compatible
order by case when myTable.myID = 35 then 1
              when myTable.myID = 15 then 2
              when myTable.myID = 25 then 3

however, the most universal approach would be to just reorder in php code.

$products = array(35,15,25);//the ordered array
$records = array_flip($products);
foreach ($list as $row) {
    $id = $row['Product']['id'];
    $records[$id] = $row;
}
print_r($records);

I'm not familiar with cake or its database layers, but maybe you can add a little bit of sql.

The relevant sql would be something like

order by field(myTable.myID, 35, 15, 25)
-- or alternatively, more cross database compatible
order by case when myTable.myID = 35 then 1
              when myTable.myID = 15 then 2
              when myTable.myID = 25 then 3
         end

however, the most universal approach would be to just reorder in php code.

$products = array(35,15,25);//the ordered array
$records = array_flip($products);
foreach ($list as $row) {
    $id = $row['Product']['id'];
    $records[$id] = $row;
}
print_r($records);
Source Link
goat
  • 31.8k
  • 7
  • 75
  • 96

I'm not familiar with cake or its database layers, but maybe you can add a little bit of sql.

The relevant sql would be something like

order by field(myTable.myID, 35, 15, 25)
-- or alternatively, more cross database compatible
order by case when myTable.myID = 35 then 1
              when myTable.myID = 15 then 2
              when myTable.myID = 25 then 3

however, the most universal approach would be to just reorder in php code.

$products = array(35,15,25);//the ordered array
$records = array_flip($products);
foreach ($list as $row) {
    $id = $row['Product']['id'];
    $records[$id] = $row;
}
print_r($records);