Iklekid Posted March 16, 2003 Share Posted March 16, 2003 Hi, I have a table in my database that has players details, one set of these details are crystal_asteroids and metal_asteroids! I was wondering if their was a mysql query that I could run that would add the value 1000 to each of details. It msut add it to every player in the table! For example if player 34 had currently 354 crystal_asteroids and 354 metal_asteroids, I would like to add 1,000 of each so he has a nw total of 1,354 crysatl_asteroids and 1,354 metal asteroids. To manually change this for every player is very time consumming as seen as there is over 100 players! Is there a query I could run then?? Thanks Very much in advance Iklekid Quote Link to comment Share on other sites More sharing options...
metalblend Posted March 16, 2003 Share Posted March 16, 2003 This should do the trick:[php:1:60596a6f97]<?php # assuming you have all these fields: # id = user id # crystal_asteroids = number of crystal asteroids # metal_asteroids = number of crystal asteroids $resultGET = mysql_query(\"SELECT (id,crystal_asteroids,metal_asteroids) FROM table ORDER BY id ASC\") or die(mysql_error()); while ($row = mysql_fetch_array($resultGET)) { $newCA = $row[\'crystal_asteroids\']+1000; $newMA = $row[\'metal_asteroids\']+1000; mysql_query(\"UPDATE table SET (crystal_asteroids=\'\".$newCA.\"\',metal_asteroids=\'\".$newMA.\"\') WHERE id=\'\".$row[\'id\'].\"\'\") or die(mysql_error()); } ?>[/php:1:60596a6f97] Hope that helps. Quote Link to comment Share on other sites More sharing options...
Iklekid Posted March 16, 2003 Author Share Posted March 16, 2003 Thanks for your reply, once sorting the ariables in the code I end up with this <?php # assuming you have all these fields: # id = user id # crystal_asteroids = number of crystal asteroids # metal_asteroids = number of crystal asteroids $resultGET = mysql_query("SELECT (id,crystal_asteroids,metal_asteroids) FROM pa_users ORDER BY id ASC") or die(mysql_error()); while ($row = mysql_fetch_array($resultGET)) { $newCA = $row[\'crystal_asteroids\']+1000; $newMA = $row[\'metal_asteroids\']+1000; mysql_query("UPDATE pa_users SET (crystal_asteroids=\'".$newCA."\',metal_asteroids=\'".$newMA."\') WHERE id=\'".$row[\'id\']."\'") or die(mysql_error()); } ?> Unfortunately when I execute the file i get this error You have an error in your SQL syntax near \'crystal_asteroids,metal_asteroids) FROM pa_users ORDER BY id ASC\' at line 1 Any Ideas? Thnask very much :-) Quote Link to comment Share on other sites More sharing options...
metalblend Posted March 16, 2003 Share Posted March 16, 2003 Sorry, take out the parenthesis in both queries: $resultGET = mysql_query("SELECT id,crystal_asteroids,metal_asteroids FROM pa_users ORDER BY id ASC") or die(mysql_error()); and mysql_query("UPDATE pa_users SET crystal_asteroids=\'".$newCA."\',metal_asteroids=\'".$newMA."\' WHERE id=\'".$row[\'id\']."\'") or die(mysql_error()); Hope that helps. Quote Link to comment Share on other sites More sharing options...
Iklekid Posted March 17, 2003 Author Share Posted March 17, 2003 thanks very much it worked, except for one thing, when I run it it changes all accounts mines to 1,000 of each! it dosent add on their original amount of mines they had before for example planet a has 234 metal mines 364 crystal mines when i run the script it then sets its values as 1000 metal mines 1000 crystal mines I want it to set it as 1234 metal mines 1364 metal mines Thanks for your continued help! Iklekid Quote Link to comment 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.