2012-11-25 146 views
0

我該如何使這個顯示最近的用戶第一?PHP/MYSQL顯示數據庫

<?php 

$host="mysql13.000webhost.com"; // Host name 
$username="a2670376_Users"; // Mysql username 
$password="PASSWORD"; // Mysql password 
$db_name="a2670376_Pass"; // Database name 
$tbl_name="passes"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

// select record from mysql 
$sql="SELECT * FROM $tbl_name"; 
$result=mysql_query($sql); 
?> 
<table background='https://lh6.ggpht.com/DFABQFuYSXLBiB6qlvDPfOONOUxCiwM6_S- dHnjW82iognQToTkORsy7RVXsAz0Y23w=w705' width='50%'> 
<tr> 
<th align='left'>Submition</th><th align='center'>ScreenName</th><th  align='right'>Password</th> 
</tr> 
<tr> 
<th align='left'> 
<hr color='lime' width='100%'/> 
</th> 
<th align='center'> 
<hr color='lime' width='100%'/> 
</th> 
<th align='right'> 
<hr color='lime' width='100%'/> 
</th> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
?> 

<tr> 
<td background='transparent' align='left'><i><b><? echo $rows['id']; ?></b></i></td> 
<td background='transparent' align='center'><i><b><? echo $rows['username']; ?></b></i> </td> 
<td background='transparent' align='right'><i><b><? echo $rows['password']; ?></b></i> </td> 
</tr> 

<?php 
// close while loop 
} 
?> 

</table> 

<?php 
// close connection; 
mysql_close(); 
?> 
<center> 

所以,當這是在我的網站上跑了就說明它像這樣

1 username password 

2 username password 

3 username password 

我想讓它顯示這樣

3 username password 

2 username password 

1 username password 

最新的第一,我似乎無法想出來

請不要發佈像使用mysqli或其不安全的東西我知道,我會解決它一旦我得到它的查詢工作corectly

回答

4

變化:

// select record from mysql 
$sql="SELECT * FROM $tbl_name order by id desc"; 
+0

非常感謝救了我很多麻煩 –

+0

歡迎您。然後標記爲接受的答案:) – Habibillah

+2

@ user1837896如果Habibillah的答案解決了您的問題,請單擊此帖子左側的刻度線並接受答案... – NazKazi