简体   繁体   中英

PHP/MYSQL show database

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

I want it to show like this

3 username password

2 username password

1 username password

the most recent first and I cant seem to figure it out

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

change your query to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM