I have a PHP script that runs daily, loops through all users to send them a text, and updates their status. It's basically like this...(pseudo-code)
$sql="SELECT UserPhone from users WHERE Status='LOW'";
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
// loop through and send texts
}
// then update status
$sql="UPDATE users SET Status='MED'";
I can detect whether the text was sent successfully, and I'd like to only update the user's status if the text was successful. My first instinct is to move the UPDATE into the while loop and update each user's row individually, something like this, pseudo-code again:
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
$sent=sendText($phone);
if($sent) {
$sql=UPDATE users SET Status='MED' WHERE UserPhone=$phone";
}
}
This feels clunky to me and I'm guessing isn't good for performance. It feels like I should be able to store/remember which texts sent and update all those users with a single UPDATE (or at least something that doesn't require a new UPDATE for every row).
I know just enough MySQL to do dumb stuff with it. Is there a better way to do this?