我從數據庫中選擇數據並將其顯示在頁面上。
未保存在數據庫中的一個有用值是$position
。 顯示每個運動員的位置很有用,這裏顯示的數字只是顯示增加的$i
值。
代碼如下ORDERS BY run points
。問題是,當按照其他事物排序列表時,例如ORDER BY athlete ASC
,分配給每個運動員的位置不隨運動員移動。選擇運動員數據的MySQL數據庫需要位置
$selectproduct = mysqli_query($link, "SELECT `athlete`,`reference`,SUM(`Run Points`) AS 'Run Points',COUNT(`eventID`) AS 'num_runs',`Volunteer Points`,`location`,`Gender pos` FROM `Events` WHERE `Gender`='$Gender' AND `location`='$location' GROUP BY `reference` ORDER BY `Run Points` DESC");
while ($rowGetDetails = mysqli_fetch_array($selectproduct)){
$reference=$rowGetDetails['reference'];
$athlete=$rowGetDetails['athlete'];
$points=$rowGetDetails['Run Points'];
$num_runs=$rowGetDetails['num_runs'];
$position=$i;
echo '<tr>';
echo'<td>';
echo $athlete;
echo '</td>';
echo'<td>';
echo $num_runs;
echo '</td>';
echo'<td>';
echo $points;
echo '</td>';
echo '</tr>';
$i=$i+1;
}
當別的東西排序,如athlete ASC
在$selectproduct
它仍然給$postition
作爲該列表中的第一位運動員與一個名稱數量1一開始的時候,是不是得分最多運動員。
還有其他選項$selectproduct
如下面通過athlete ASC
排序:
$selectproduct = mysqli_query($link, "SELECT `athlete`,`reference`,SUM(`Run Points`) AS 'Run Points',COUNT(`eventID`) AS 'num_runs',`Volunteer Points`,`location`,`Gender pos` FROM `Events` WHERE `Gender`='$Gender' AND `location`='$location' GROUP BY `barcode` ORDER BY `athlete` ASC"
我覺得你的查詢看起來不錯 – JYoThI
您正在通過跑分排序 – maSTAShuFu
謝謝你,當'排序的查詢工作正常運行點數「,但在排序時,如」ORDER BY athlete ASC「等其他排序,運動員的位置不會移動。我將編輯我的問題以使其更清晰 – Jeanclaude