Jump to content

Add values to all columns


Iklekid

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.