2011-12-07 34 views
0

我想按位置按字母順序排序我的SQL數據庫。我在phpMyAdmin網站上執行了命令:SELECT * FROM users ORDER BY location,現在用戶確實按照位置在線數據庫按字母順序排列。但是,他們仍然不會在我們的網站上按字母順序顯示。這裏是我輸出相關的SQL數據的代碼:正確顯示排序的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> 

我在做這個代碼錯了嗎?我想以與訂購在線數據庫相同的順序顯示錶格,但它不起作用。

+1

我不明白爲什麼你錯過了「命令按地點「。你甚至提到你從mysql命令行中使用它。 – Matt

回答

1

更改:

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

到:

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

你缺少查詢中的ORDER BY location

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