0
我試圖使用ORDER BY DESC
結果排序,但結果被foreach
值排序:有兩個表PHP排序值導致
while($row = mysqli_fetch_array($sqlgroup)){
$member_array = $row["member_array"];
if ($member_array !=""){
$memberArray = explode(",", $member_array);
$i = 0;
$cashstatsList .= '
';
foreach($memberArray as $gkey => $mvalue){
$i++;
$arraystats = "SELECT player.first_name, player.last_name, SUM(groupcash.grpcsh_earnings) AS memsum, AVG (groupcash.grpcsh_earnings) AS memavg,
SUM(groupcash.grpcsh_w) AS memcntpos, SUM(groupcash.grpcsh_l) AS memcntneg
FROM player, groupcash
WHERE (player.id = grpcsh_plrid) AND (player.id = $mvalue) AND (groupcash.grpcsh_groupid = $groupid)
AND (grpcsh_date >= '$thisyr') AND (grpcsh_date <= '$today') ORDER BY SUM(groupcash.grpcsh_earnings) DESC
";
$arraystatsResutls = mysqli_query($link, $arraystats);
if (!$arraystatsResutls){
$cashstatsList .= '
<tr>
<td>
No results available for listed dates
</td>
</tr>';
} else {
while($row = mysqli_fetch_array($arraystatsResutls)){
$memberFirstName = $row["first_name"];
$memberLastName = $row["last_name"];
$sum = $row["memsum"];
$avg = $row["memavg"];
$win = $row["memcntpos"];
$loss = $row["memcntneg"];
if ($memberFirstName == "" || $memberLastName == ""){
$sqlName = mysqli_query($link, "SELECT first_name, last_name FROM player WHERE id='$mvalue' LIMIT 1") or die ("Sorry we had a mysql error!");
while ($row = mysqli_fetch_array($sqlName)) {
$memberFirstName = $row["first_name"]; $memberLastName = $row["last_name"];
}
}
if ($sum == ""){
$sum = "0";
}
if ($avg == ""){
$avg = "0";
}
if ($win == ""){
$win = "0";
}
if ($loss == ""){
$loss = "0";
}
$cashstatsList .= '
<tr align="center">
<td>
' . $i . '
</td>
<td>
' . $memberFirstName . ' ' . $memberLastName . '
</td>
<td>
$' . $sum . '
</td>
<td>
$' . $avg . '
</td>
<td>
' . $win . '/' . $loss . '
</td>
</tr>';
}
}
}
}
}
什麼是第一個查詢被循環 – Ibu