穿过阵列我做了一个基本的夹具发生器,它也为每个团队的分数输入生成输入字段。目标是让这些分数更新排名表。从表格
我快到了,但我坚持一个组成部分。注意:下面的代码故意不会更新排行榜或暂时发送分数,因为我只是想先测试输出以确保其正常工作。
我提交的灯具页上的分数,一旦我提出,我有一个是通过每一行(EG战队1-12,二队-15)应该循环回路,并制定出优胜者。现在问题出在哪里 - 我的循环只返回最后一排得分并计算出胜利者,然后重复(队2获胜者)19次(有19排固定装置)
我不能工作out是我的数据在循环的每次迭代中是否被覆盖,或者可能(我认为这更可能),它只考虑最后一行,因为数据不是以正确的数组格式能够。遍历
下面是一些代码注释$团队是从以前的网页表单输入数组(用户键入队名,而这下面的代码产生夹具名单,与框输入分数);
$counter=0;
foreach ($teams as $team) {
foreach ($teams as $opposition) {
if ($team != $opposition) {
$str = <<<EOF
<input type="hidden" name="team1" value="$team[1]">
<input type="hidden" name="team2" value="$opposition[1]">
<tr><td>Row $counter<input type="hidden" value="$counter" name="row1"><td><input type="hidden" name="team_id" class="invis" value="$team[0]"><td><input type="text" name="team1_score"> $team[1]
<td> versus <td> <input type="hidden" value="$opposition[0]"><td> $opposition[1] <td><input type="text" name="team2_score"><td>Row $counter<input type="hidden" value="$counter" name="row2"></tr>
<input type="hidden" name="fixtures" value="$counter">
EOF;
echo $str;
$counter++;
}
}
}
echo "<hr><input type=\"submit\" value=\"Go\">";
echo "</form>";
echo "</table>";
,现在我与有问题的代码,它输出的最后一行一次得分,然后输出抽奖/赢/输报表19倍(灯具数量)...
$team1=$_POST['team1'];
$team2=$_POST['team2'];
$row1=$_POST['row1'];
$row2=$_POST['row2'];
$fixtures=$_POST['fixtures'];
$team_id=$_POST['team_id'];
$team1_score=$_POST['team1_score'];
$team2_score=$_POST['team2_score'];
$games=$_POST['games'];
$games=array('TeamOne: ' =>$team1, 'Goals: '=> $team1_score, 'TeamTwo: ' => $team2, 'Goals2: '=>$team2_score);
$row=0;
while ($row<$fixtures) {
foreach ($games as $key=>$value) {
echo "$key $value <br>";
}
if ($team1_score > $team2_score) {
echo "$team1 are the winners";
$row++;
}
else if ($team2_score > $team1_score) {
echo "$team2 are the winners";
$row++;
}
else {
echo "Drawed";
$row++;
}
}
因此,这会输出球队和比分,然后(取决于比分)重复获胜者或抽奖选项19次。
任何帮助将不胜感激。
非常感谢
啊这么简单 - 非常感谢! – DJC