Преглед изворни кода

Add ability to set default column in order_by() function.

Nate пре 6 година
родитељ
комит
4f894f0f81
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      resources/functions.php

+ 2 - 1
resources/functions.php

@@ -2124,10 +2124,11 @@ function number_pad($number,$n) {
 
 
 //validate and format order by clause of select statement
 //validate and format order by clause of select statement
 	if (!function_exists('order_by')) {
 	if (!function_exists('order_by')) {
-		function order_by($col, $dir) {
+		function order_by($col, $dir, $col_default = '') {
 			$col = preg_replace('#[^a-zA-Z0-9-_.]#', '', $col);
 			$col = preg_replace('#[^a-zA-Z0-9-_.]#', '', $col);
 			$dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
 			$dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
 			if ($col != '') { return ' order by '.$col.' '.$dir.' '; }
 			if ($col != '') { return ' order by '.$col.' '.$dir.' '; }
+			else if ($col_default != '') { return ' order by '.$col_default.' '.$dir.' '; }
 		}
 		}
 	}
 	}