我的問題是,當我在瀏覽器中運行代碼時,爲什麼HW1/HW2/HW3列有空白值?
Studentid和Sum列正確顯示代碼。任何理想的如何解決這個問題?使用MySQL/PHP的總和列
<?php
$result = mysqli_query($con,"SELECT studentid,SUM(hw1+hw2+hw3)
FROM grade
GROUP BY studentid");
echo "<table border='1'>
<tr>
<th>StudentID</th>
<th>HW1</th>
<th>HW2</th>
<th>HW3</th>
<th>SUM</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['studentid'] . "</td>";
echo "<td>" . $row['hw1'] . "</td>";
echo "<td>" . $row['hw2'] . "</td>";
echo "<td>" . $row['hw3'] . "</td>";
echo "<td>" . $row['SUM(hw1+hw2+hw3)'] . "</td>";
;}
echo "</table>";
mysqli_close($con);
?>
謝謝大家。對不起,我上面寫的英文不好。所有建議都是正確的。 – user2227817