瀏覽代碼

limit_offset() function refinement

Nate 6 年之前
父節點
當前提交
75d8c45d58
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      resources/functions.php

+ 3 - 4
resources/functions.php

@@ -2133,15 +2133,14 @@ function number_pad($number,$n) {
 
 //validate and format limit and offset clause of select statement
 	if (!function_exists('limit_offset')) {
-		function limit_offset($limit, $offset) {
+		function limit_offset($limit, $offset = 0) {
 			$regex = '#[^0-9]#';
 			$limit = preg_replace($regex, '', $limit);
 			$offset = preg_replace($regex, '', $offset);
 			if (is_numeric($limit) && $limit > 0) {
 				$clause .= ' limit '.$limit;
-				if (is_numeric($offset)) {
-					$clause .= ' offset '.$offset;
-				}
+				$offset = is_numeric($offset) ? $offset : 0;
+				$clause .= ' offset '.$offset;
 			}
 			return $clause.' ';
 		}