0

如何使此显示首先显示最近的用户?

<?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或不安全之类的东西我知道,一旦我让它正常工作,我会修复它

4

1 回答 1

4

将您的查询更改为:

// select record from mysql 
$sql="SELECT * FROM $tbl_name order by id desc";
于 2012-11-25T09:01:12.877 回答