From 6ddb5a17ae1a0a75ca75f846dbb7d3a98f1902a3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 17:22:50 +0000 Subject: Added 'random' as an order_by() option in Active Record. --- system/database/DB_active_rec.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'system/database/DB_active_rec.php') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index cb134ea6a..e8059ab76 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -450,7 +450,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function order_by($orderby, $direction = '') { - if (trim($direction) != '') + if (strtolower($direction) == 'random') + { + $orderby = ''; // Random results want or don't need a field name + $direction = $this->_random_keyword; + } + elseif (trim($direction) != '') { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } @@ -458,6 +463,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_orderby[] = $orderby.$direction; return $this; } + // -------------------------------------------------------------------- /** @@ -469,6 +475,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->order_by($orderby, $direction); } + // -------------------------------------------------------------------- /** @@ -583,7 +590,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - $sql = $this->_compile_select($this->count_string); + $sql = $this->_compile_select($this->_count_string); $query = $this->query($sql); $this->_reset_select(); -- cgit v1.2.3-24-g4f1b