Here's what I have. This code grabs the data from all of the users and subtracts 1 from user_days then updates every user's user_days row.
$result = mysqli_query($con,"SELECT * FROM users");
while($row = mysqli_fetch_array($result))
{
$minusone = $row['user_days']-1;
mysqli_query($con,"UPDATE users SET user_days=$minusone");
echo "<br />";
echo $row['user_days'];
}
The problem I'm having is this: Instead of subtracting 1 from each user and updating each users field, it's updating each user's field with the value from the first user.
example: before updating user 1 has 30 days user 2 has 60 days
after updating user 1 has 29 days user 2 has 29 days (instead of 59 days)
Any help is appreciated and I hope this question is easy to understand.
Just to clarify, I DO want to update every field. I just don't want the updates to be duplicated from the first result.
Thanks for all of the answers, this has given me a lot of help.
update users set user_days=$minusone where id=.$row[id]or whatever. Moreover, you do not need to do that in the loop. Try something likeupdate users set user_days=user_days-1;standalone.