<?php require_once('./config/connection.php'); //找出所有队伍 $xtteam=mysql_query("SELECT tid FROM team"); //$row=mysql_fetch_row($xtteam);将每个队伍保存到数组中 while($row=mysql_fetch_row($xtteam)){ foreach ($row as $allcy) { $allcy=mysql_query("SELECT total FROM member where team_id=$row ");//先找出同一队的所有成员 $cj=0; while($memrow=mysql_fetch_row($allcy)){ foreach ($memrow as $mycj) { $cj=$cj+$mycj; } $resultteam=mysql_query("UPDATE team set score=$cj where tid=$row "); if($resultteam&&mysql_affected_rows()>0){ echo "<br />Update <br />"; }else{ echo "False".mysql_errno()." Why:".mysql_error()."<br />"; } } } } ;?>
描述:一个组队答题系统,想把每个队伍的每个人的分数汇总后更新到团队分数表中
先列出所有团队
在列出每个团队的所有人
再将每个人的分数累积起来
然后更新到team表分数score
表有team表
tid
score
成员表member
id
total
team_id
Notice: Array to string conversion in on line 8
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given 10