summaryrefslogtreecommitdiffstats
path: root/system/database/DB_active_rec.php
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2007-12-18 18:22:50 +0100
committerDerek Allard <derek.allard@ellislab.com>2007-12-18 18:22:50 +0100
commit6ddb5a17ae1a0a75ca75f846dbb7d3a98f1902a3 (patch)
tree1192959a689fc65b6995abbedb51c7c92730fdfa /system/database/DB_active_rec.php
parent694b5b8ee6a40b57c91be3c5448bc8f5540d32d8 (diff)
Added 'random' as an order_by() option in Active Record.
Diffstat (limited to 'system/database/DB_active_rec.php')
-rw-r--r--system/database/DB_active_rec.php11
1 files changed, 9 insertions, 2 deletions
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();