我有一个表单可以更新两个团队之间的分数。 我想更新达到确切分数的人的分数。 我想检查某人是否确实做了然后添加积分。 如果我为一个人做它的工作,但我想检查和添加多个用户
我试图解决它,但我找不到答案..
if(isset($_POST['submit'])){
$result = mysql_query("UPDATE `match` SET
`match`.`home_goal` = '".$_POST['home_goal']."',
`match`.`away_goal` = '".$_POST['away_goal']."'
WHERE `match`.`id` = '".$_POST['gameid']."'");
$result2 = mysql_query(
"SELECT * FROM `match_guess` WHERE
`match_guess`.`match_id` = '".$_POST['gameid']."'");
while($row2 = mysql_fetch_array($result2)){
if($_POST['home_goal'] == $row2['home_goals'] &&
$_POST['away_goal'] == $row2['away_goals']) {
$result3 = mysql_query("UPDATE `members` SET
`members`.`acc` = `members`.`acc` + 1,
`members`.`points` = `members`.`points` + 5
WHERE `members`.`id` = '".$row2['user_id']."'");
}
}
}
答案 0 :(得分:0)
你没有在while循环中执行$ result3,所以它被覆盖了。 $ result3(或者更确切地说,$ sql3)应该在循环外定义并附加在循环内部并在循环之后执行
$sql3 = "UPDATE `members`
SET `members`.`acc` = `members`.`acc` + 1,
`members`.`points` = `members`.`points` + 5
WHERE `members`.`id` = '0'";
while(...) {
if(...){
$sql3 .= " OR `members`.`id` = '".$row2['user_id']."'";
}
}
$result3 = mysql_query($sql3);