Merged changes from master branch up to current state.
[fa-stable.git] / includes / db_pager.inc
index b9e7e75927445b30fc45140cc9bbe72119a542ca..70243392f75e53096ca1c1de63af72fa901c30fc 100644 (file)
@@ -300,11 +300,8 @@ class db_pager {
                }
                if ($where) $where = " WHERE ($where)";
 
-               if ($count) {
-                       $group = $group == '' ? "*" : "DISTINCT $group";
-
-                       return "SELECT COUNT(*) FROM (SELECT $group FROM $from $where) tmp_count";
-               }
+               if ($count)
+                       return "SELECT COUNT(*) FROM ($this->sql) tmp_count";
 
                $sql = "$select FROM $from $where";
                if ($group) $sql.= " GROUP BY $group";
@@ -316,8 +313,8 @@ class db_pager {
                                        if(isset($col['ord_priority'])) {
                                                $columns[$col['ord_priority']] = $col;
                                        }
-                       }
-                       krsort($columns);
+               }
+               krsort($columns);
 
            foreach ($columns as $col) {
                if (isset($col['ord'])) {
@@ -326,7 +323,7 @@ class db_pager {
                            }
                        }
            }
-                               
+
            if (count($ord)) {
                        $ord = array_map('db_escape_function', $ord);
                        $sql .= " ORDER BY " . implode(',', $ord);