I have a soccer fantasy league php script, there is 20 teams and more than 400 players assigned to the teams, and I have 500 users.
Every week there is a points should be assigned to each player, so that in the end every user will have a total points from his formation and that will generate the ranking for the season.
First week points were added normally, but for the second week point the addpont section became so slow, and for the 3rd week points a socket time out error appears.
here is the code I'm using in adding points to users:
// Adding Point To the user player list
$sql_user="select * from ".$prev."user LIMIT 0, 100 ";
$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);
}
}
}
}
I've limited the number of users to 100 user every submitting and even so the code still slow.
the slowness is only with this code other website sections are working normally.
Is there any way to write the code in other faster way, or if there is any thing else I can do?
many thanks in advance,