如何从我的查询 COUNT 中获取结果。
这就是我在数据库中查询的样子
fname lname mname positionName COUNT(tbl_votes.studId)
jr gwapo is-very chairman 2
这就是我的网页的外观
Name Position Number of Votes
jr is-very gwapo chairman ______
这是我的代码。
<?php
if ($result = $mysqli->query("SELECT tbl_student.fname, tbl_student.lname, tbl_student.mname, tbl_position.positionName, Count(tbl_votes.studId) FROM tbl_candidate Inner Join tbl_student ON tbl_candidate.studId = tbl_student.studId Inner Join tbl_position ON tbl_candidate.positionId = tbl_position.positionId Inner Join tbl_votes ON tbl_student.studId = tbl_votes.candId WHERE tbl_position.positionId = '1' GROUP BY tbl_student.fname, tbl_student.lname, tbl_student.mname, tbl_position.positionName")) {
if ($result->num_rows > 0) {
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>Name</th><th>Position</th><th>Number of Votes</th></tr>";
while ($row = $result->fetch_object()) {
echo "<tr>";
echo "<td>" . $row->fname . " " . $row->mname . " " . $row->lname . " </td>";
echo "<td>" . $row->positionName . "</td>";
//this is where i suppose to echo the count result
echo "<td>" . $row-> ??? . "</td>";
echo"<tr>";
}
echo "</table>";
} else {
echo "No results to display!";
}
}
$mysqli->close();
?>
这是我的问题,我怎么能在 "echo "" 中传递 "Count(tbl_votes.studId)" 。 $row-> ??? . ""; " ?请帮助...