[英]How to filter the rows by points. PHP/MySQL
伙計們 我有以下腳本
<?php
$result = mysql_query("SELECT * FROM players") or die(mysql_error());
echo "<table class=\"table table-bordered table-hover\" border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Place</th> <th>Name</th> <th>Points</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['place'] . '</td>';
echo '<td>' . $row['name'] . '</td>';
echo '<td>' . $row['points'] . '</td>';
echo '<td><a href="wtawomenedit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="deleter.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
該腳本顯示了MySQL表中的所有內容,但是行是混合的,並且當我將其用於范圍列表時,我想顯示按點過濾的行。 具有較高點的行位於第一位,依此類推。 預先謝謝您,我還沒有做任何事情。 像以前那樣,所以我不知道如何使它工作。
您需要按點...按降序對結果進行排序
$result = mysql_query("SELECT * FROM players ORDER BY points DESC")
;
查詢中的用戶ORDER BY
首先獲取更高積分。
嘗試這個...
$result = mysql_query("SELECT * FROM players ORDER BY points DESC");
在SQL中,有一個ORDER BY選項,您可以在這種情況下使用。
對於最大到最小
$result = mysql_query("SELECT * FROM players ORDER BY points DESC") ;
對於最小到最大
$result = mysql_query("SELECT * FROM players ORDER BY points ASC") ;
您必須將mysql qyuery編輯為
SELECT *
FROM players
ORDER BY points DESC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.