#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    8
    Rep Power
    0

    Question about MySQL


    Hello there, I've a gaming community.
    And am trying to make something through the MySQL database, I want to set their money to a specific number, depends on the current money.

    For example if someone has $10 milion, I want to set it to $1 million, is there any code to search for users with 10million and replace it to 1milion?

    It was just an example, i need a code like this to search for a specific number and replace it to another number.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,434
    Rep Power
    9645
    UPDATE
    Code:
    UPDATE table SET field = new number WHERE field = old number
    Make sure you actually want "replace 10M with 1M" and not, say, "replace >1M with 1M".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    8
    Rep Power
    0
    Alright, i will check it when am back home.
    (Pcash (Table name) = for player's cash)

    UPDATE Pcash SET field = 1.000.000 WHERE field = 10.000.000
    Is it right?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,402
    Rep Power
    394
    No, remove the dots from the numeric literals. Whole numbers in SQL are written without punctuation.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    8
    Rep Power
    0
    Oh, alright will try it when am back home thanks.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2015
    Location
    Canada
    Posts
    24
    Rep Power
    0
    It's worth running a quick SELECT with the same WHERE clause, before you run the update so you can see the records that will be affected by the UPDATE.
    For example:
    SELECT * FROM Pcash WHERE field = 1000000

    Comments on this post

    • r937 agrees

IMN logo majestic logo threadwatch logo seochat tools logo