正确显示排序的SQL行


Properly Displaying Sorted SQL Rows

我正试图按位置按字母顺序排序我的SQL数据库。我在phpMyAdmin网站上执行命令:SELECT * FROM users ORDER BY location,并且用户现在确实按在线数据库上的位置按字母顺序排序。然而,他们仍然没有按字母顺序显示在我们的网站上。下面是我输出相关SQL数据的代码:

<div>
  <table id="checkintable">
    <tr>
        <th>Name</th>
        <th>Location</th>
        <th>Comment</th>
    </tr>                  
  <? $result = mysql_query("SELECT fullname, location, comment FROM users"); ?>
  <? while ($row = mysql_fetch_array($result)): ?>
    <tr class="tables">
        <td><?= $row["fullname"]?></td>
        <td><?= $row["location"]?></td>
        <td><?= $row["comment"]?></td>
    </tr>
    <br>
  <? endwhile ?>
  </table>
</div>

我在这段代码中做错了什么吗?我想以与在线数据库相同的顺序显示表,但它不工作

您的查询中缺少ORDER BY location:

$result = mysql_query("SELECT fullname, location, comment FROM users ORDER BY location");

更改您的:

mysql_query("SELECT fullname, location, comment FROM users")

:

mysql_query("SELECT fullname, location, comment FROM users ORDER BY location")