瀏覽代碼

#615 Fixed bug on multi column queries - wrong count resulting in strange effects in the display of results

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2422 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 年之前
父節點
當前提交
56392558d5
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      core/sqlquery.class.inc.php

+ 7 - 2
core/sqlquery.class.inc.php

@@ -311,8 +311,13 @@ class SQLQuery
 		{
 			if (count($aSelectedIdFields) > 0)
 			{
-				$sIDFields = implode(', ', $aSelectedIdFields);
-				$sSQL = "SELECT COUNT(DISTINCT $sIDFields) AS COUNT FROM $sFrom WHERE $sWhere";
+				$aCountFields = array();
+				foreach ($aSelectedIdFields as $sFieldExpr)
+				{
+					$aCountFields[] = "COALESCE($sFieldExpr, 0)"; // Null values are excluded from the count
+				}
+				$sCountFields = implode(', ', $aCountFields);
+				$sSQL = "SELECT COUNT(DISTINCT $sCountFields) AS COUNT FROM $sFrom WHERE $sWhere";
 			}
 			else
 			{