我有3所学校,学生和投票机构。我想从所有已注册特定主题的学校(例如计算机型号)中按student_id搜索学生。计数。结果应列出所有学校和注册学生的人数。
结果看起来像这样
-ID School_Name校长联系学校No_Registered_to_Vote
$sql = "SELECT *,COUNT(leconst_name)
FROM schools LEFT JOIN regStudent ON schools.const_name=regStudent.leconst_name
LEFT JOIN voters ON (voters.student_id=regStudent.regStudent_id)
GROUP BY schools.school_name";
$result = $conn->query($sql);
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['school_name'] . "</td>";
echo "<td>" . $row['Headteacher'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['school'] . "</td>";
echo "<td>" . $row['COUNT(leconst_name)'] . "</td>";