我想将表格排序到正确的部分。我有一个用户数据库,他们都有分配给每个用户的等级。在每个部分中都应该有一个表格,显示该等级中的所有用户。例如:
管理器
ID | rank | username | email | password
---------------------------------------------------
70 | Manager | MyUser | email@mail.com | pswrd
---------------------------------------------------
70 | Manager | MyUser | email@mail.com | pswrd
管理
ID | rank | username | email | password
---------------------------------------------------
9 | Admin | userName | email@email.com | pswrd22
我想使用while循环来制作它。到目前为止我所拥有的:
<html>
<head>
</head>
<?php
$tUsers_Select = "SELECT * FROM users LEFT JOIN ranks ON ranks.rankName = users.rank";
$tRanks_Select = "SELECT * FROM ranks";
$tUsers_Select_Query = mysqli_query($dbConnect, $tUsers_Select);
$tRanks_Select_Query = mysqli_query($dbConnect, $tRanks_Select);
?>
<body>
<?php
while ($users_item = mysqli_fetch_array($tUsers_Select_Query, MYSQL_ASSOC)) {
$ID = $users_item['ID'];
$rank = $users_item['rank'];
$username = $users_item['username'];
$email = $users_item['email'];
$password = $users_item['password'];
}
while ($ranks_item = mysqli_fetch_array($tRanks_Select_Query, MYSQL_ASSOC)) {
$rankName = $ranks_item['rankName'];
$value = $ranks_item['value'];
echo '<h2>'.$rankName.'</h2>';
}
?>
<table border="1">
<tr>
<td>ID</td>
<td>rank</td>
<td>username</td>
<td>email</td>
<td>password</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
如果您需要更多详情,请发表评论。
答案 0 :(得分:0)
准备好的陈述会更好。但是你走了
<?php
$tRanks_Select = "SELECT `rankName` FROM `ranks`";
$tRanks_Select_Query = mysqli_query($dbConnect, $tRanks_Select);
while ($ranks_item = mysqli_fetch_array($tRanks_Select_Query, MYSQL_ASSOC)) {
$rankName = $ranks_item['rankName'];
echo '<h2>'. $rankName .'</h2>';
while ($users_item = mysqli_fetch_array($tUsers_Select_Query, MYSQL_ASSOC)) {
$tUsers_Select = "SELECT `ID`, `rank`, `username`, `email`, `password` FROM `users` WHERE `rank` = '{$rankName}'";
$tUsers_Select_Query = mysqli_query($dbConnect, $tUsers_Select);
$ID = $users_item['ID'];
$rank = $users_item['rank'];
$username = $users_item['username'];
$email = $users_item['email'];
$password = $users_item['password'];
echo <<<EOD
<table border="1">
<tr>
<td>ID</td>
<td>rank</td>
<td>username</td>
<td>email</td>
<td>password</td>
</tr>
<tr>
<td>$ID</td>
<td>$rank</td>
<td>$username</td>
<td>$email</td>
<td>$password</td>
</tr>
</table>
EOD;
}
}
?>