diff --git a/CRM/Report/Form/Contribute/History.php b/CRM/Report/Form/Contribute/History.php index b97f1adb5c3c..4b310b05b012 100644 --- a/CRM/Report/Form/Contribute/History.php +++ b/CRM/Report/Form/Contribute/History.php @@ -608,14 +608,19 @@ public function buildRows($sql, &$rows) { $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$receive_date} = {$this->_referenceYear['this_year']} AND contri.is_test = 0 AND contri.is_template = 0 ) "; } $this->limit(); - $getContacts = "SELECT {$this->_aliases['civicrm_contact']}.id as cid, SUM({$this->_aliases['civicrm_contribution']}.total_amount) as civicrm_contribution_total_amount_sum {$this->_from} {$this->_where} {$addWhere} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_having} {$this->_limit}"; + $getContacts = "SELECT {$this->_aliases['civicrm_contact']}.id as cid, SUM({$this->_aliases['civicrm_contribution']}.total_amount) as civicrm_contribution_total_amount_sum {$this->_from} {$this->_where} {$addWhere} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_having}"; + // Run it without limit/offset first to get the right number of rows for + // the pager. + CRM_Core_DAO::executeQuery($getContacts); + $this->setPager(); + + $getContacts .= ' ' . $this->_limit; $dao = CRM_Core_DAO::executeQuery($getContacts); while ($dao->fetch()) { $contactIds[] = $dao->cid; } - $this->setPager(); $relationshipRows = []; if (empty($contactIds)) {