marcus Posted January 5, 2007 Share Posted January 5, 2007 I'm making a game, and I want to update ever users points count and add 20,000 points to it.[code]<?phprequire('../connect.php');$sql = "SELECT * FROM `users`";$res = mysql_query($sql);$row = mysql_fetch_assoc($res);$points = $row[points];echo $points;?>[/code]When I echo $points it only shows the first row. Would it just be simply using a while statement to do this or could I just update like this? Quote Link to comment https://forums.phpfreaks.com/topic/33011-updating-every-row/ Share on other sites More sharing options...
Psycho Posted January 5, 2007 Share Posted January 5, 2007 <?phprequire('../connect.php');$sql = "SELECT * FROM `users`";$res = mysql_query($sql);while ($row = mysql_fetch_assoc($res)) { $points = $row[points]; echo $row[userID]."<br>"; echo " Old Points: ".$points; echo "<br> New Points: ".($points+20000); $sql = "UPDATE `users` SET points = ".($points+20000)." WHERE userID = ".$row[userID]; mysql_query($sql);}?> Quote Link to comment https://forums.phpfreaks.com/topic/33011-updating-every-row/#findComment-153712 Share on other sites More sharing options...
ToonMariner Posted January 5, 2007 Share Posted January 5, 2007 or just$sql = "UPDATE `users` SET `points` = `points` + 20000"; mysql_query($sql);the above may fail as you may be restricted to teh number of queries you can run in one script - this query will do the lot all at once.To show them all you need[code]<?phprequire('../connect.php');$sql = "SELECT * FROM `users`";$res = mysql_query($sql);while ($row = mysql_fetch_assoc($res)){ echo $row[points] . "<br />";}?>[/code]That while statement is a prime candidate for putting all that info into a table - that way you can see the username etc. etc. (you will have to echo out each field in teh table - not just teh points). Quote Link to comment https://forums.phpfreaks.com/topic/33011-updating-every-row/#findComment-153717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.