所以我目前正在为我的社区构建一个新的CMS,并遇到了一个小问题。我希望能够将命令链中最高级别的排名列为最低,但我无法使用基于字符串的排名来解决这个问题。
<?php
include "dbh.php";
include "header.php";
$sql = "SELECT * FROM users_leo";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$rank = $row["rank"];
$department = $row["department"];
?>
<div class="login-page">
</div>
<div class='form'>
<?php
$sql = "SELECT * FROM users_leo";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<th>In-Game Name</th>
<th>Rank</th>
<th>Department</th>
<th>Profile</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>"; echo $row['username']; echo"</td>";
echo "<td>"; echo $row['username']; echo"</td>";
echo "<td>"; echo $row['department']; echo"</td>";
echo '<td><a class="viewProfile" href="profile.php?id=' . $row['id']. '"><button>View Profile</button></a></td>';
echo "</tr>";
}
}
?>
</div>
</div>
</body>
正如您可以在下面的代码中看到的那样,等级存储为字符串
echo "<select name='rank'>
<option value='Corrections Officer'>Corrections Officer</option>
<option value='Senior Corrections Officer'>Senior Corrections Officer</option>
<option value='DOC Corporal'>DOC Corporal</option>
<option value='DOC Sergeant'>DOC Sergeant</option>
<option value='DOC Lieutenant'>DOC Lieutenant</option>
<option value='DOC Head Lieutenant'>DOC Head Lieutenant</option>
<option value='DOC Command'>DOC Command</option>
<option value='Trooper 3rd class'>Trooper 3rd Class</option>
<option value='Trooper 2nd class'>Trooper 2nd Class</option>
<option value='Trooper 1st class'>Trooper 1st Class</option>
<option value='Lance Corporal'>Lance Corporal</option>
<option value='State Corporal'>State Corporal</option>
<option value='State Sergeant'>State Sergeant</option>
<option value='First Sergeant'>First Sergeant</option>
<option value='2nd Lieutenant'>2nd Lieutenant</option>
<option value='1st Lieutenant'>1st Lieutenant</option>
<option value='State Command'>State Command</option>
<option value='Officer'>Officer</option>
<option value='Senior Officer'>Senior Officer</option>
<option value='Police corporal'>Police Corporal</option>
<option value='Police Sergeant'>Police Sergeant</option>
<option value='Staff Sergeant'>Staff Sergeant</option>
<option value='Police Lieutenant'>Police Lieutenant</option>
<option value='Police Head Lieutenant'>Police Head Lieutenant</option>
<option value='PD Command'>PD Command</option>
<option value='Overseer'>Overseer</option>
</select>
我已经尝试过但无法找到解决方案P.S.如果有人可以解释如何设置它以便将它们显示为字符串,我愿意将所有等级更改为数字。
答案 0 :(得分:0)
如果你想从最高到最低的顺序选择字符串,那么代码ASC [升序降级]和DESC [降序升序]
SELECT * FROM users_leo ORDER BY column_name ASC [or] DESC;