If I have a script like this:
$sql = "SELECT * FROM table WHERE Status='0'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query))
$id = $row['ID'];
//.........
if($process->send()) { //after sent
mysql_query("UPDATE table
SET Status ='1'
WHERE ID = '$id'");
}
}
So it will update each row when process is done.But if I have more than ten thousand records with the Status='0'
, the update will become slow .
So is there any better way to update the record? I can't update all with one single query since I need to know whether each process is done or not.
Thank you.
Add all successful ones to an array and simply commit all of those simultaneously.
if ($process->send()) {
$done[] = $id;
}
and a bit later:
mysql_query('UPDATE table SET Status=1 WHERE ID IN ('.implode(',', $done).')');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With