summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-13 02:01:42 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-13 02:01:42 +0100
commit98e46cf96447a2a6448d8dc984948a8694dbf747 (patch)
tree360accab5158416e6672224b8762052d5398d7e1 /user_guide_src/source/database
parent9e94576e62e9edb5634cb3f4d278038069bb70a8 (diff)
Add seed values support for Query Builder order_by
(feature request #1987)
Diffstat (limited to 'user_guide_src/source/database')
-rw-r--r--user_guide_src/source/database/query_builder.rst30
1 files changed, 23 insertions, 7 deletions
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.