当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Listing all users from database, with multiple columns & ascending order

问题描述:

In short, a leaderboard.

The person with the highest coins wants to be listed, first. listing the top 10 only, based on the highest coin count joined with their username.

This lists the usernames, but not sure how to get their coins count, as well as ascend them in a top 10 formation.

<?php

$query = mysql_query("SELECT username FROM `users`");

echo '<table>';

while($rowtwo = mysql_fetch_array($query)){

echo '<tr>

<td><font size="2" face="Lucida Sans Unicode" color="red">'.$rowtwo['username'].'</td>

</tr>';

}

echo '</table>';

?>

网友答案:
SELECT username FROM `users` ORDER BY coins DESC LIMIT 10

The DESC is important or else it will list coins in order of lowest to highest. This also assumes that coin count is a column of users. If it's not, you'll have to let me know.

网友答案:

Change the query to:

SELECT username FROM `users` ORDER BY `coins` DESC LIMIT 0,10
分享给朋友:
您可能感兴趣的文章:
随机阅读: