﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc	difficulty
379	get_entities_from_metadata: count returns wrong number of records	pillgrim		"In both get_entities_from_metadata and get_entities_from_metadata_multi, count() returns wrong number of entities. I've found the problem and a solution at http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html, here is a solution for Elgg:

{{{
Index: engine/lib/metadata.php
===================================================================
--- engine/lib/metadata.php     (revision 57)
+++ engine/lib/metadata.php     (working copy)
@@ -517,7 +517,7 @@
                if (!$count) {
                        $query = ""SELECT distinct e.* "";
                } else {
-                       $query = ""SELECT count(e.guid) as total "";
+                       $query = ""SELECT count(distinct e.guid) as total "";
                }

                $query .= ""from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid where"";
@@ -622,7 +622,7 @@
                        $where[] = ""e.container_guid = {$owner_guid}"";

                if ($count) {
-                       $query = ""SELECT count(e.guid) as total "";
+                       $query = ""SELECT count(distinct e.guid) as total "";
                } else {
                        $query = ""SELECT distinct e.* "";
                }
}}}
"	Defect	closed	critical	Elgg 1.1	Core	1.0	critical	fixed	sql, count	brettp	
