我有一个足球幻想联盟脚本,每周我都会使用以下代码向用户添加一个积分:
$sql_user="select * from ".$prev."user ";
$re_user=mysql_query($sql_user);
while($d_user=mysql_fetch_array($re_user))
{
$userID=$d_user['id'];
$sql_addpointgroup="select * from ".$prev."addpoint group by weekno order by weekno";
$re_addpointgroup=mysql_query($sql_addpointgroup);
while($d_addpointgroup=mysql_fetch_array($re_addpointgroup))
{
$points=0;
$sql_addpoint="select * from ".$prev."addpoint where weekno='".$d_addpointgroup['weekno']."'";
$re_addpoint=mysql_query($sql_addpoint);
while($d_addpoint=mysql_fetch_array($re_addpoint))
{
$points=$d_addpoint['points'];
$sql_weekstatistic="select * from ".$prev."weekstatistic where weekno='".$d_addpointgroup['weekno']."' and userID='$userID' and playerID='".$d_addpoint['playerID']."'";
$re_weekstatistic=mysql_query($sql_weekstatistic);
if(mysql_num_rows($re_weekstatistic)>0)
{
$sql_update="update ".$prev."weekstatistic set points='$points' where weekno='".$d_addpointgroup['weekno']."' and userID='$userID' and playerID='".$d_addpoint['playerID']."'";
mysql_query($sql_update);
}
}
}
}
一开始这段代码运行良好,但注册用户数达到 500 个用户后,现在更新过程非常缓慢,并且有时会出现超时错误消息。
有没有办法重写这段代码,以便更快地完成更新过程?
提前谢谢了,