2014-02-20 25 views
-1

因此,我嘗試使用ORDER BY,但無法使其工作。我想訂購帳戶名的字母順序如何在.php(mysql)中按字母順序排列

$field1=mysql_result($result,$i,"id"); 
$field2=mysql_result($result,$i,"steamId"); 
$field3=mysql_result($result,$i,"accountName"); 

$query2="SELECT * FROM Times WHERE steamId='$field2'"; 
$result2=mysql_query($query2); 
$field4=mysql_numrows($result2); 

只是想簡單的A-Z

+0

檢查ORDER BY ASC/DESC – Naeem

回答

1

使用它像

$query2 = "SELECT * FROM Times WHERE steamId='$field2' ORDER BY accountName"; 

注意Order By defaultly採取Ascending訂單。

+1

「警告:mysql_numrows()預計參數1是資源,在布爾給出players.php上線38」(與相同웃웃웃웃웃的回答) – MrX

+0

38將是:$ field4 = mysql_numrows($ result2); (在我的最後一行) – MrX

+0

使用像mysql_num_rows($ result2); – Gautam3164

1
SELECT * FROM Times WHERE steamId='$field2' order by accountName asc 
0

*

有兩種方法來分類: - 升序和降序排列。

**按升序排列的數據查詢會

: - ** SELECT * FROM時報WHERE steamId = '$ FIELD2' ORDER BY帳戶名

** * *對於降序的數據查詢將是: - **

** SELECT * FROM Times WHERE steamId ='$ field2'ORDER BY accountName DESC。

*