diff options
Diffstat (limited to 'user_guide_src')
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 | ||||
-rw-r--r-- | user_guide_src/source/database/query_builder.rst | 30 |
2 files changed, 24 insertions, 7 deletions
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 1a80f76a3..d03419fbb 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -126,6 +126,7 @@ Release Date: Not Released - Added an optional parameter that allows to disable escaping (useful for custom fields) for methods ``join()``, ``order_by()``, ``where_in()``, ``or_where_in()``, ``where_not_in()``, ``or_where_not_in()``, ``insert()``, ``insert_batch()``. - Added support for ``join()`` with multiple conditions. - Added support for *USING* in ``join()``. + - Added seed values support for random ordering with ``order_by(seed, 'RANDOM')``. - Changed ``limit()`` to ignore NULL values instead of always casting to integer. - Changed ``offset()`` to ignore empty values instead of always casting to integer. - Methods ``insert_batch()`` and ``update_batch()`` now return an integer representing the number of rows affected by them. diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst index 61cd7dfed..8fb906052 100644 --- a/user_guide_src/source/database/query_builder.rst +++ b/user_guide_src/source/database/query_builder.rst @@ -469,25 +469,41 @@ Identical to having(), only separates multiple clauses with "OR". $this->db->order_by() ===================== -Lets you set an ORDER BY clause. The first parameter contains the name -of the column you would like to order by. The second parameter lets you -set the direction of the result. Options are asc or desc, or random. +Lets you set an ORDER BY clause. + +The first parameter contains the name of the column you would like to order by. + +The second parameter lets you set the direction of the result. +Options are **ASC**, **DESC** AND **RANDOM**. :: - $this->db->order_by("title", "desc"); // Produces: ORDER BY title DESC + $this->db->order_by('title', 'DESC'); + // Produces: ORDER BY `title` DESC You can also pass your own string in the first parameter:: - $this->db->order_by('title desc, name asc'); // Produces: ORDER BY title DESC, name ASC + $this->db->order_by('title DESC, name ASC'); + // Produces: ORDER BY `title` DESC, `name` ASC Or multiple function calls can be made if you need multiple fields. :: - $this->db->order_by("title", "desc"); - $this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC + $this->db->order_by('title', 'DESC'); + $this->db->order_by('name', 'ASC'); + // Produces: ORDER BY `title` DESC, `name` ASC + +If you choose the **RANDOM** direction option, then the first parameters will +be ignored, unless you specify a numeric seed value. + +:: + + $this->db->order_by('title', 'RANDOM'); + // Produces: ORDER BY RAND() + $this->db->order_by(42, 'RANDOM'); + // Produces: ORDER BY RAND(42) .. note:: order_by() was formerly known as orderby(), which has been removed. |