From 3b93fcff3c45347859f40ce03b8eafb92566424e Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Mon, 12 Nov 2012 14:34:39 +0000 Subject: [PATCH] #615 Fixed bug on multi column queries - wrong count resulting in strange effects in the display of results SVN:trunk[2422] --- core/sqlquery.class.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/sqlquery.class.inc.php b/core/sqlquery.class.inc.php index 32b3119f0..2d45d205b 100644 --- a/core/sqlquery.class.inc.php +++ b/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 {