diff options
Diffstat (limited to 'system/database/DB_query_builder.php')
-rw-r--r-- | system/database/DB_query_builder.php | 13 |
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; |