I am having problem archiving real time loop. While it going to next iteration, it should check the status first for an update (status= 0) before going to next iteration.
status field might be updated somewhere else…
For example:
<?php
$SQL = "SELECT * FROM data WHERE status = 0";
$query = $db->prepare($SQL);
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
print("\n\n");
sleep(5);
}
?>
While php script is running/looping, in mysql console, I quickly did:
UPDATE data SET status = 1
It is still showing all the records even I have updated the status. How can that problem be fixed?
The result set is only computed once. If you want to see intermediate updates, you need to issue another SELECT statement.