我想在while循環中運行while循環,但只顯示單行。爲什麼while循環顯示單行?
<?php
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT u.id, u.firstname, u.lastname, u.email, c.fullname, ro.shortname, c.id as courseid
from mdl_context cx
Left join mdl_course c ON cx.instanceid = c.id
Left join mdl_role_assignments r on r.contextid = cx.id
Left join mdl_user u on u.id = r.userid
Left join mdl_role ro on ro.id = r.roleid
WHERE r.roleid IN (11)
AND cx.contextlevel =50 GROUP BY u.id ORDER BY u.id ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<table>"."<tr>"."<td width='100px;'><h4>Name</h4></td>"."<td width='50px;'>"."</td>"."<td width='230px;'><h4>Email</h4></td>"."<td width='100px;'><h4>Role</h4></td>"."<td width='100px;'>"."</td>"."<td><h4>Course</h4></td>"."</table>"."<br>";
while($tmg = $result->fetch_assoc()) {
echo "<table>"."<tr>"."<td width='100px;'><a href='http://localhost/user/profile.php?id=".$tmg["id"]."'>".$tmg["firstname"]." ".$tmg["lastname"]."</a></td>"."<td width='50px;'>"."</td>"."<td width='230px;'>".$tmg["email"]."</td>"."<td width='100px;'>".$tmg["shortname"]."</td>";
while($row = $result->fetch_assoc()) {
echo "<td width='100px;'>"."</td>"."<td>".$row["fullname"]."</td>"."</table>"."<br>";
}
}
} else {
echo "0 results";
}
$conn->close();
?>
任何指導或幫助將不勝感激。
怎麼樣執行另一個查詢'$ sqlt' –
沒有定義這個「$ sqlt」或者它只是一個錯字:P – Sherlock
怎麼樣的另一個查詢? – MOZ