I'm trying to put the user_value in an array if the affiliate_id=50. Then add up the array with the sum function. The issue is the array only has one of the user values inside it.
My question is how do I add all the user_values together (in an array) WHERE the affiliate_id=50?
Currently only one user_value is added to the array.
$sql = mysqli_query($conn, "SELECT user_value FROM active_users WHERE affiliate_id=50");
$affiliate_total_earnt = array(mysqli_fetch_assoc($sql));
echo array_sum($affiliate_total_earnt);
You can summarize values directly in MySQL:
$query = "SELECT sum(user_value) as sum FROM active_users WHERE affiliate_id=50";
$result = mysqli_query($conn, $query);
$affiliate_total_earn = mysqli_fetch_assoc($result)['sum'];
echo "Affiliate total earn: " . $affiliate_total_earn;
Try code here PHPize.online
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.