0
我有一个用户表和高尔夫锦标赛的分数表为这些用户。当用户参加锦标赛时,他会使用表单在结果表中记录一个分数。我想显示一个结果表格,显示用户的完整列表和比赛中的分数。表格中有八列分数 - 每个球场都有一列。我正在努力用PHP代码来显示结果分数。如果玩家已经玩过,他的得分正确显示,但是如果表中的下一名玩家没有玩过他的得分,则表示为表中他之上的玩家的得分。这继续下去,直到遇到真正的分数。我试图找到没有成功的答案。这是我的代码,只有一门课程。如果我能克服这个问题,我相信这些代码将适用于其他课程。foreach loops给出意想不到的结果
$query = "SELECT * FROM emg_users ORDER BY user_login";
$results=mysql_query($query);
$results_array = array();
while ($row = mysql_fetch_array($results)) {
$results_array[$row['ID']] = $row;
}
foreach ($results_array as $id => $record) {
$player = $record['user_login'];
?>
<tr>
<td class="padded_c" nowrap="nowrap"><?php echo $player;?></td> <!-- Player name -->
<?php
$query = "SELECT * FROM 0_tournament_test WHERE player = '".$player."' AND course = 'St_Andrews'";
$results=mysql_query($query);
$results_array = array();
while ($row = mysql_fetch_array($results)) {
$results_array[$row['id']] = $row;
}
foreach ($results_array as $id => $record) {
$pplayer = $record['player'];
if ($pplayer = $player) {
$sta = $record['score'];
}
else {
unset($sta);
}
$id++;
}
?>
<td class="padded_c" nowrap="nowrap"></td>
<td nowrap="nowrap"><?php echo $sta;?></td>
<td nowrap="nowrap"><?php echo $rsg;?></td>
<td nowrap="nowrap"><?php echo $bet;?></td>
<td nowrap="nowrap"><?php echo $oak;?></td>
<td nowrap="nowrap"><?php echo $kia;?></td>
<td nowrap="nowrap"><?php echo $cng;?></td>
<td nowrap="nowrap"><?php echo $mer;?></td>
<td nowrap="nowrap"><?php echo $oly;?></td>
<td nowrap="nowrap"><?php echo $allshots;?></td>
<td nowrap="nowrap"><?php echo $sss;?></td>
<td nowrap="nowrap"><?php echo '';?></td>
</tr>
<?php
$id++;
}
?>
</table>
仍然没有工作遵循这个修正案,但感谢回复 –
你的意思是'unset($ sta);'???? 您是否想要使用'$ sta =''''来清空'$ sta'值.. –
或者您想总结玩家的分数... 要比添加'$ sta + = $ record ['score' ];' –