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

This commit is contained in:
Nate 2019-08-02 21:11:30 -06:00
parent 9d9ad19578
commit c0f129d5de
1 changed files with 2 additions and 1 deletions

View File

@ -2124,10 +2124,11 @@ function number_pad($number,$n) {
//validate and format order by clause of select statement
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);
$dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
if ($col != '') { return ' order by '.$col.' '.$dir.' '; }
else if ($col_default != '') { return ' order by '.$col_default.' '.$dir.' '; }
}
}