I have a table -'Zombie' with users in... They have a certain amount of 'Money' I want this page to update their money by + 15, every time the page is ran (Will be a cron job) But, I cant get it to work... The 2nd user gets the same '$newmoney' as the first user -So in the MySQL database they have the same money -which is incorrect... Can anyone fix this code so it works? Or adapt it? -Or show me a better way to do it... (I'm sort off new to php) $query = ("SELECT * FROM `Zombie`"); $result = mysql_query($query); $numrows= mysql_num_rows($result); $count = 0; while ($count < $numrows) { $count = $count + 1; $query = ("SELECT * FROM `Zombie` WHERE `Id` = '$count' "); $row = mysql_fetch_array($result); $money = $row['Money']; $newmoney = $money + 15; $result = mysql_query($query); mysql_query("UPDATE Zombie SET `Money` = '$newmoney' WHERE `Id` = '$count'"); } Thanks, James
You don´t need an array.. mysql will calculate Money+15 for all users just by using that query.. you don´t need any other code for that.
all of this $query = ("SELECT * FROM `Zombie`"); $result = mysql_query($query); $numrows= mysql_num_rows($result); $count = 0; while ($count < $numrows) { $count = $count + 1; $query = ("SELECT * FROM `Zombie` WHERE `Id` = '$count' "); $row = mysql_fetch_array($result); $money = $row['Money']; $newmoney = $money + 15; $result = mysql_query($query); mysql_query("UPDATE Zombie SET `Money` = '$newmoney' WHERE `Id` = '$count'"); } PHP:
Haha ok thanks -working now Never new you could update more than one row with one query -Now I know. thanks