I have a while loop with a sleep function that I wan´t to run -> update database -> sleep -> run again for a number of 10 times. With the below script the script loops 10 times, but it only updates the database when all 10 loops have finished.
I added an echo at the end just to verify, and the echo does not appear on the page until the and when every loop is echoed out at once.
I have also tried placing ob_flush() and flush() after the echo with no luck.
Script
$loops = 10;
while ($loops > 0)
{
while($row = mysql_fetch_array($result))
{
// Get current User status
$username = $row['username'];
$user_status = $row['user_status'];
$user_updated = date('Y-m-d H:i:s');
// Update database
$update_sql = "UPDATE `database`.`user` SET `user_status` = '$user_status',
`user_updated` = '$agent_updated'
WHERE
`user`.`username` = '$username'";
$update=mysql_query($update_sql);
echo "Loop #".$loops."<br>";
}
flush();
$loops--;
Sleep(5);
}
I've also tried the same with a FOR loop.
Any suggestions would be appreciated. I've gone through the search and haven´t found users with similar issues but I couldn't find the answer.