- ⌂ query
- Methods
query::order_by()
Add one or more fields or expressions to the query ORDERY BY clause. The order_by method takes any number of field parameters.
Prototype
order_by(mixed $expressions): query
Parameters
- expressions - An array of strings and/or arrays. Each element in the main array must be a string or array.
- Elements that are strings are dot-notation field names, optionally followed by a space and ASC or DESC to determine the order.
- Elements that are arrays can contain:
- One or two strings, first the dot-notation field name, and optionally second ASC or DESC to determine the order.
- A cQL Array, optionally followed by a string containing ASC or DESC to determine the order.
Return
The updated query object is returned. This is handy for chaining additional methods.
Example
// equivalent to ORDER BY Field
$query->order_by(['Field']);
// equivalent to ORDER BY Field DESC
$query->order_by([['Field', 'DESC']]);
// equivalent to ORDER BY MAX(Field)
$query->order_by([[['MAX', 'Field']]]);
// equivalent to ORDER BY MAX(Field) DESC
$query->order_by([[['MAX', 'Field']], 'DESC']);
// equivalent to ORDER BY MAX(Field) DESC, OID ASC
$query->order_by([[['MAX', 'Field'], 'DESC'], ['OID', 'ASC']]);