Answers for "Custom Order By in CakePHP"

PHP
2

Custom Order By in CakePHP

// In mysql you can order by specific field values, by using ORDER BY FIELD:
SELECT * FROM city 
WHERE id IN (10, 1, 2)
ORDER BY FIELD(id, 10, 1, 2) DESC;

// output:
// order: first those with id = 10, those with id = 1, those with id = 2
// Do in cake
	'order' => array(
		'FIELD(City.id, 10, 1, 2)',
	),

// or
    'order' => array(
		'FIELD(City.id, 10, 1, 2) DESC',
	),
Posted by: Guest on December-14-2020

Browse Popular Code Answers by Language