我整天都在为这个问题撞墙,我知道该怎么做。我希望这不是很简单,因为这对我来说是一场斗争!我已经搜索了一整天,希望有人可以帮助我。
我有一个 html 表格,显示训练营中每个球员的体能测试结果。我已经弄清楚如何将它们连同它们的名称一起显示(取自另一个 mysql 表)。现在,在每个测试结果旁边,我想添加它们对特定测试结果的排名。这是现在减去过滤部分的代码(我认为不需要它来解决这个问题):
数据库查询如下。它按位置对桌上的球员进行排序,以便所有防守队员一起出现,所有前锋一起出现,守门员一起出现,以便教练轻松查看。
//get the camp id for the coach logged in
$getcampid = "SELECT value FROM profile_values WHERE uid = '$user->uid'";
$campid = mysql_query ($getcampid);
$campidrow = mysql_fetch_array($campid);
$coachescamp = $campidrow[0];
$getplayerdata = mysql_query("SELECT * FROM content_type_test
INNER JOIN content_type_player ON content_type_test.field_player_uid=
content_type_player.field_uid
WHERE content_type_test.field_training_camp_nid='$coachescamp'
ORDER BY content_type_player.field_position_value") or die(mysql_error());
$left = true;
while($playerdata=mysql_fetch_array($getplayerdata))
{
echo "<td>", $playerdata['field_position_value'], "</td>";
echo "<td>", $playerdata['field_last_name_value'],", ",$playerdata['field_first_name_value'], "</td>";
echo "<td>", $playerdata['field_speed_value'], "</td>";
echo "<td>Show rank of players speed compared to other players in $getplayerdata query</td>";
echo "<td>", $playerdata['field_agility_value'], "</td>";
echo "<td>Show rank of players agility compared to other players in $getplayerdata query</td>";
echo"</tr>";
}
echo"</tbody></table>";
我需要在“显示玩家等级......”的列中显示玩家速度和敏捷度的等级。总共还有 5 个等级,我需要在该表中显示,我没有包括在内,以保持简单。如果我能看到如何为这两个做这件事,我就可以为其他人做这件事。
注意:速度和敏捷是数字。数组中的最低数字应排名第一。
感谢您提供的任何帮助,这些帮助一直在杀死我。
编辑 - - - - - - - - - - - - - - - - - - -
这是我只返回 1 个结果的代码
$getplayerdata = mysql_query("SELECT * FROM content_type_test
INNER JOIN content_type_player ON content_type_test.field_player_uid=
content_type_player.field_uid
WHERE content_type_test.field_training_camp_nid='$coachescamp'
ORDER BY content_type_player.field_position_value") or die(mysql_error());
$left = true;
while($playerdata=mysql_fetch_array($getplayerdata))
{
$arrayOfAllData = array();
while($playerdata=mysql_fetch_array($getplayerdata)){
$arrayOfAllData[$playerdata[ID]] = array(field_position_value =>$playerdata['field_position_value'],
field_last_name_value=>$playerdata['field_last_name_value'],
field_speed_value=>$playerdata['field_speed_value']);
}
$sql = mysql_query("SELECT @rownum:=@rownum+1 'rank', * FROM content_type_test, (SELECT @rownum:=0) r
INNER JOIN content_type_player ON content_type_test.field_player_uid=
content_type_player.field_uid
WHERE content_type_test.field_training_camp_nid='$coachescamp'
ORDER BY content_type_player.field_speed_value");
while($playerdata=mysql_fetch_array($sql)){
$arrayOfAllData[$playerdata[ID]]["field_speed_value"] = $playerdata['field_speed_value'];
}
foreach($arrayOfAllData as $player){
echo "<td>", $player['field_position_value'], "</td>";
echo "<td>", $player['field_last_name_value'],", ",$player['field_first_name_value'], "</td>";
echo "<td>", $player['field_speed_value'], "</td>";
echo "<td>*I dont know what to put here to display the rank*</td>";
echo"</tr>";
}
}
echo"</tbody></table>";
打印显示一行这样的数组([] => 数组([field_position_value] => Forward [field_last_name_value] => Tester [field_speed_value] => 4.504))
同样如一栏中所述,我不知道该键入什么来显示排名。