Jump to content


Photo

Add values to all columns


  • Please log in to reply
4 replies to this topic

#1 Iklekid

Iklekid
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationUK

Posted 16 March 2003 - 11:34 AM

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
Webmaster of Dark Wars
[br]http://www.dwog.net

#2 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 16 March 2003 - 07:44 PM

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.

#3 Iklekid

Iklekid
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationUK

Posted 16 March 2003 - 08:05 PM

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 :-)
Webmaster of Dark Wars
[br]http://www.dwog.net

#4 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 16 March 2003 - 09:57 PM

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.

#5 Iklekid

Iklekid
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationUK

Posted 17 March 2003 - 07:11 PM

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
Webmaster of Dark Wars
[br]http://www.dwog.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users