My php code is very slow and timeout error appears
<p>I have a soccer fantasy league script and every week I add a points to the users, using this code:</p>

<pre><code>$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)&gt;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);
    }
  }
}   
}
</code></pre>

<p>in the beginning this code was working fine, but after the number of registered users reached the 500 users, the updating process now is very slow and some times timeout error msg appears.</p>

<p>Is there any way to rewrite this code, so to do the updating process faster?</p>

<p>many thanks in advance,</p>
