Jump to content

Archived

This topic is now archived and is closed to further replies.

Iklekid

Add values to all columns

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

Share this post


Link to post
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.

Share this post


Link to post
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 :-)

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.