PHP/MYSQL显示数据库 [英] PHP/MYSQL show database
本文介绍了PHP/MYSQL显示数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使此显示首先显示最近的用户?
how do I make this display the most recent users first?
<?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>
所以当它在我的网站上运行时,它会像这样显示
so when this is ran on my website it shows it like this
1 username password
2 username password
3 username password
我希望它显示为
3 username password
2 username password
1 username password
最近的第一,我似乎无法弄清楚
the most recent first and I cant seem to figure it out
请不要发布诸如使用mysqli
之类的内容,否则它不安全,我知道这一点,我将在其正常工作后予以修复
please don't post things like use mysqli
or its not safe I know that and I will fix it once I get it to work corectly
推荐答案
将查询更改为:
// select record from mysql
$sql="SELECT * FROM $tbl_name order by id desc";
这篇关于PHP/MYSQL显示数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文