summaryrefslogtreecommitdiffstats
path: root/system/database/DB_query_builder.php
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 /system/database/DB_query_builder.php
parent9e94576e62e9edb5634cb3f4d278038069bb70a8 (diff)
Add seed values support for Query Builder order_by
(feature request #1987)
Diffstat (limited to 'system/database/DB_query_builder.php')
-rw-r--r--system/database/DB_query_builder.php13
1 files changed, 8 insertions, 5 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 364397721..543d5ccdd 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1144,13 +1144,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/
public function order_by($orderby, $direction = '', $escape = NULL)
{
- $direction = trim($direction);
+ $direction = strtoupper(trim($direction));
- if (strtolower($direction) === 'random' OR $orderby === $this->_random_keyword)
+ if ($direction === 'RANDOM')
{
- // Random ordered results don't need a field name
- $orderby = $this->_random_keyword;
$direction = '';
+
+ // Do we have a seed value?
+ $orderby = ctype_digit((string) $orderby)
+ ? $orderby = sprintf($this->_random_keyword[1], $orderby)
+ : $this->_random_keyword[0];
}
elseif (empty($orderby))
{
@@ -1158,7 +1161,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
elseif ($direction !== '')
{
- $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';
+ $direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';
}
is_bool($escape) OR $escape = $this->_protect_identifiers;