我从数据库中选择数据并将其显示在页面上。
未保存在数据库中的一个有用值是$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