我已搜索過去3天,但找不到解決方案。我試圖計算一個數組中玩家最低5分的總分,我嘗試過array_sum,但我無法讓它工作,不管我嘗試什麼,只顯示數組的5個最低值,但不會將它們加在一起,這裏是代碼。PHP mysqli計算數組結果的總數
<?php
if (isset($_POST['calc'])) {
$player = $_SESSION['id'];
$result = $conn->query("SELECT * FROM scores WHERE player_id='$player' ORDER by points ASC");
$row = $result->fetch_array();
$row_count = mysqli_num_rows($result);
if ($row_count>=10) { // checks that at least 10 rows available
$result = $conn->query("SELECT points FROM scores WHERE player_id='$player' ORDER by points ASC LIMIT 5"); // select 5 lowest points
while ($row = mysqli_fetch_array($result)) {
$total = array($row['points']);
$sum = array_sum($total);
echo $sum;
}
你的價值謝謝,我會嘗試,並獲得給予反饋表格。非常感謝您的幫助。 –