用户使用我们的程序注册团队,然后输入他们每天/每周/等行走的里程数。此外,在程序期间我们举办小型活动。事件将包含带有QR码的传单,用户扫描代码并输入其信息。一旦他们这样做,用户就会因为参加该活动而获得荣誉。该网站的点数系统取决于他们参加的活动,以及他们走了多少英里。
我有两个表存储需要对它们求和的两个不同变量,然后每个表使用一个除法来确定该总和的点值,然后将其放入一个排行榜表,并将其放入按点数降序排列。
目前,按行进里程,它按降序排序。
关于如何解决这个问题的任何理想?我想的可能是某种阵列魔法,我将每个用户的信息存储到一个数组中,然后将其拉出来,但我对如何开始使用它并不理想。
存储的用户名存储在表中:Team_Assign
用户的步行里程存储在表格中:Miles
用户的参加活动存储在表格中:活动
我内心地将这三张桌子加在一起。
10英里是1点,2个事件是1点。
约翰走了10英里,有4场比赛,这将是3分 简有20英里和1场比赛,这将是2.5分目前,它按谁拥有最多里程进行排序,我理解为什么会这样,但我不知道如何重做查询以使其按照在while循环期间建立的点进行排序。
John 3
Jane 2.5
Jane 2.5
John 3
<?php
$Count = 0;
$LB_User_Query = " SELECT Miles_User, Team_Assign_Name, SUM(Miles_Amount) AS 'Miles', SUM(Event_Count) AS 'Event_Count2'
FROM Team_Assign
INNER JOIN Miles ON Team_Assign_User = Miles_User
INNER JOIN Event ON Team_Assign_User = Event_User
GROUP BY Miles_User, Team_Assign_User, Team_Assign_Name
ORDER BY Miles, Event_Count2 Desc";
$LB_User_stmt = $conn->prepare($LB_User_Query);
$LB_User_stmt->execute();
$LB_User_stmt->bind_result($Miles_User, $Team_Assign_Name, $Miles, $Event_Count2);
while (mysqli_stmt_fetch($LB_User_stmt))
{
$User_Miles = $Miles;
$Count = $Count + 1;
$Miles_Points_indc = 10;
$Event_Points_indc = 1;
$Miles_Points_Total_1 = $User_Miles / $Miles_Points_indc;
$Miles_Points_Total_2 = $Miles_Points_Total_1 / $Event_Count2;
$Event_Points_Total = $Event_Count2 / $Event_Points_indc;
$Total_Points = $Miles_Points_Total_2 + $Event_Points_Total;
$Total_Points_Round = round($Total_Points, 2);
echo'<tr>';
echo'<td>'.$Count.'</td>
<td>'.$Team_Assign_Name.'</a></td>
<td>'.$Total_Points_Round .'</td>';
echo'</tr>';
}
?>
答案 0 :(得分:1)
您需要为按您排序的每列应用单独的desc
修饰符:
$LB_User_Query = " SELECT Miles_User, Team_Assign_Name, SUM(Miles_Amount) AS 'Miles', SUM(Event_Count) AS 'Event_Count2'
FROM Team_Assign
INNER JOIN Miles ON Team_Assign_User = Miles_User
INNER JOIN Event ON Team_Assign_User = Event_User
GROUP BY Miles_User, Team_Assign_User, Team_Assign_Name
ORDER BY Miles DESC, Event_Count2 Desc";
# missing here --------------------^