I’m working in PHP, and I have a list of ids, which are ranked, with the first being the most important. I’m retrieving the rows using something like this (simplified for clarity):
$id_as_sql_list = implode("','", $id_list);
$sql = "SELECT * FROM books
WHERE id in ('$id_as_sql_list')";
This basically works out as:
WHERE id in ('456', '123', '789')
The problem is, the result from the database isn’t coming back in the order of the list. What’s the best way to get them back in this order?
Take a look at order by field syntax.
This is an example