我想要的是echo "<p>Average Mark: $average</p>";
出現在表格上方而不是在表格下方。如果我這樣做,雖然問題是它不會計算平均值,因爲回聲高於變量。但是,如果我將變量和整個表格上方的while循環移動(我需要while循環來從查詢中選擇$row[Mark]'
字段,因爲這是要進行平均的字段),它會混淆表。我如何在表格上方顯示$average, $total, $count
等變量和echo "<p>Average Mark: $average</p>";
而不會搞亂表格結構?重新顯示一個回顯和變量會搞亂我的表?
我試圖$("#record").html(<?php echo "Average Mark: $average"; ?>);
但我得到這個錯誤在這條線: 解析錯誤:語法錯誤,意外「(」,希望T_VARIABLE或/web/stud/u0867587/Mobile_app/exam_grade_report.php「$」上線135
下面是當前的代碼,你可以看到在while循環的$count++; , $total += $row['Mark'];
和$平均變動和回聲底部
<?php
$result = mysql_query($query);
mysql_close();
$("#record").html(<?php echo "Average Mark: $average"; ?>);
?>
<div id="record">
<table border='1'>
<tr>
<th>Session ID</th>
<th>TeacherUsername</th>
<th>Teacher Name</th>
<th>Module Number</th>
<th>Module Name</th>
<th>Course ID</th>
<th>Course Name</th>
<th>Year</th>
<th>Student Username</th>
<th>Student Name</th>
<th>Mark</th>
<th>Grade</th>
</tr>
<?php
$total = 0;
$count = 0;
while ($row = mysql_fetch_array($result)) {
$count++;
$total += $row['Mark'];
echo "
<tr>
<td>{$row['SessionId']}</td>
<td>{$row['TeacherUsername']}</td>
<td>{$row['TeacherForename']} {$row['TeacherSurname']}</td>
<td>{$row['ModuleId']}</td>
<td>{$row['ModuleName']}</td>
<td>{$row['CourseId']}</td>
<td>{$row['CourseName']}</td>
<td>{$row['Year']}</td>
<td>{$row['StudentUsername']}</td>
<td>{$row['StudentForename']} {$row['StudentSurname']}</td>
<td>{$row['Mark']}</td>
<td>{$row['Grade']}</td>
</tr>";
}
?>
</table>
</div>
<?php
$average = (int)($total/$count);
echo "<p>Average Mark: $average</p>";
?>
有人告訴我試試這個,不知道是什麼這意味着 – BruceyBandit