UPDATE question

Discussion in 'MySQL' started by Kodu, Apr 14, 2009.

  1. #1
    Hello fellow DP members.

    I have some questions, you see, I'm not a guru at MySQL but I'd like to learn from the ones who are :)

    So here's the question, let's say I have a table called "accounts" with column "coins" on it. Now, I want to give my users a bonus amount of coins but don't know which query to run. For example, user1 has 100 coins under his account and I want to give him 10 extra coins which would sum up to 110 in total.

    What query can I run to do this job?
    Thanks in advance :)
     
    Kodu, Apr 14, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Is the increase always 10 or 10% or does it vary by user? Also, do you want to update every user at once, or just one at a time?
     
    jestep, Apr 15, 2009 IP
  3. jimbursch

    jimbursch Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You probably need to set up another table for transactions, and store the sum of transactions in the accounts table.

    Think about it like a checking account -- transactions are recorded in your check register.

    It all depends on how much detail you need to track. If you don't need to track each transaction, then you may need just an UPDATE query:

    UPDATE accounts SET accounts.coins=accounts.coins+10 WHERE accounts.id=?
     
    jimbursch, Apr 15, 2009 IP