You could use PHP to achieve this, but this won't be necessary.
The database can do this much more efficiently
I assume your current query looks something like this
SELECT
`amount_total`,
`amount_shipping`,
`amount_partner`,
`partner`
FROM
`salesLeads`
WHERE
[..]
MySQL gives you nice aggregate functions like SUM you can use with GROUP BY
SELECT
SUM( `amount_total` ) AS `amount_total`,
SUM( `amount_shipping` ) AS `amount_shipping`,
SUM( `amount_partner` ) AS `amount_partner`.
`partner`
FROM
`salesLeads`
WHERE
[..]
GROUP BY
`partner`
in your PHP script you access this the same way but it has the final numbers grouped and summarized by partner already
e.g.
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
print_r( $row );
}
$result->close();
}
EDIT
Because you wanted a PHP solution, which again is more efficient than querying twice:
$partnerSums = array();
while ( $row = $result->fetch_assoc() ) {
if ( !array_key_exists( $row['partner'], $partnerSums ) {
$partnerSums[$row['partner']] = $row;
} else {
$partnerSums[$row['partner']]['amount_total'] += $row['amount_total'];
$partnerSums[$row['partner']]['amount_shipping'] += $row['amount_shipping'];
$partnerSums[$row['partner']]['amount_partner'] += $row['amount_partner'];
}
}
print_r( $partnerSums );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…