簡體   English   中英

如何按點過濾行。 PHP / MySQL

[英]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 

在查詢中使用ORDER BY子句。

SELECT * FROM players ORDER BY points DESC

注意: 請不要在新代碼中使用mysql_*函數 它們不再維護,已正式棄用 看到紅色框了嗎? 而是了解准備好的語句 ,並使用PDOMySQLi- 本文將幫助您確定哪一個。 如果您選擇PDO, 這是一個很好的教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM