嗨,我已经可以进行搜索了。现在我想如何根据他们的角色放置数据,基于这张图片,我想让管理员,管理员,用户,用户,用户。需要使用排序?我不知道。
这是我的编码搜索。我应该在哪里排序?
<?php
include 'config1.php';
if(isset($_POST['search'])){
$searchTerm = $_POST['search'];
$query = "SELECT * FROM members WHERE userid LIKE '%$searchTerm%'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
echo "<table height = '30%'border='1'>";
if($count == 0)
{
echo "NO ID REGISTERED!";
}
else
{
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width='5%'><b>USER ID:</b> {$row['userid']} </td>";
echo "<td width='5%'><b>USER NAME :</b> {$row['username']} </td>";
echo "<td width='5%'><b>USER EMAIL:</b> {$row['useremail']} </td>";
echo "<td width='5%'><b>USER ROLE:</b> {$row['userrole']} </td>";
echo "<td width='5%'><b>USER DIVISION:</b> {$row['userdiv']} </td>";
echo "<td width='5%'><b>USER DEPARTMENT:</b> {$row['userdepartment']} </td>";
echo "</tr>";
}
}
echo"</table>";
}
?>
答案 0 :(得分:1)
$query = "SELECT * FROM members WHERE userid LIKE '%$searchTerm%' ORDER BY userrole";
也可以使用ASC或DESC在ORDER BY之后按升序或降序显示。 例如。
Select * from users WHERE choice = 'PHP' ORDER BY id ASC;
答案 1 :(得分:0)
$query = "SELECT * FROM members WHERE userid LIKE '%$searchTerm%' order by fieldWhichYouWant";
或强>
$query = "SELECT * FROM members WHERE userid LIKE '%$searchTerm%' ORDER BY userrole ASC";
或将 ASC 或 DESC 添加为升序或降序以进行排序。
将 fieldWhichYouWant 替换为您的要求。