update sql to add "1" to a value menu

User Tag List

Results 1 to 9 of 9
  1. #1
    brange's Avatar Member
    Reputation
    16
    Join Date
    Nov 2007
    Posts
    85
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update sql to add "1" to a value

    What is the sql syntax to update a value so it increases with 1.

    Say that u got votes value=5

    and when u run the query it will be 6. and the next time 7?

    update sql to add "1" to a value
  2. #2
    tttommeke's Avatar Banned
    Reputation
    1
    Join Date
    Jul 2007
    Posts
    613
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE poll SET value++

    Not sure about it but I think this would work.

  3. #3
    brange's Avatar Member
    Reputation
    16
    Join Date
    Nov 2007
    Posts
    85
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    update fusion_users set user_votes='++' where user_id=1

    and

    update fusion_users set user_votes='value++' where user_id=1

    didnt work :P

    any other suggestions`

    edit: Got it :

    update fusion_users set user_votes = user_votes + 1 where user_id=1
    Last edited by brange; 03-15-2008 at 12:08 PM.

  4. #4
    bevin347's Avatar Member
    Reputation
    3
    Join Date
    Oct 2007
    Posts
    83
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried that... didnt wrk either

  5. #5
    latruwski's Avatar Banned
    Reputation
    647
    Join Date
    Dec 2006
    Posts
    2,456
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make a copy of your votetable... so then you have:
    votetable
    votetable_copy

    and then use this query:
    Code:
    update votetable set votes = (select votes from votetable_copy where name like '%latruwski%') + 1 where name like '%latruwski%';
    update votetable_copy set votes = (select votes from votetable where name like  '%latruwski%')  where name like  '%latruwski%';
    change votetable to your votetable name and change votetable_copy to the copy you made of the votetable.... change latruwski to the name of the person that is voting...

    tested and working ^^

    edit: here is what this exacly does:
    1) update the votetable and set votes = dummy + 1 for voter latruwski
    Dummy is like in VB programs or C++ or whatever just a aid... here the copy of the votetable is the dummy... so the query selects votes from the copied table and adds 1.
    2) Now the votetable is updated with +1 vote... now the query updates the copy of the votetable to have the same amount of votes.. so now in both tables latruwski will have +1 vote
    3) user votes again and process repeats...


    note: this is the first thing that came up to me...

    edit: instead of with a whole copy of the votes table you could also add 1 column in the votes table and use that as dummy...
    Last edited by latruwski; 04-12-2008 at 06:24 AM.

  6. #6
    krava's Avatar Member
    Reputation
    1
    Join Date
    Apr 2007
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    update fusion_users set user_votes = (user_votes + 1) where user_id=1

    and it will work. Basically it will just update previous value by adding 1

    SQL is really easy :]

  7. #7
    jaymul's Avatar Member
    Reputation
    3
    Join Date
    Mar 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OR You Can use PHP And Store The Current Value As A Varible
    Then Make Another Varible With

    $vote = "Current Value";
    $vote1 = $vote + "1";

  8. #8
    krava's Avatar Member
    Reputation
    1
    Join Date
    Apr 2007
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need, when he can directly update it via SQL. Most programmers do this mistake and have one overstep that's not needed.

  9. #9
    visitor's Avatar Contributor
    Reputation
    174
    Join Date
    Mar 2008
    Posts
    309
    Thanks G/R
    16/15
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by krava View Post
    no need, when he can directly update it via SQL. Most programmers do this mistake and have one overstep that's not needed.
    its not a mistake -.-
    Hey I just met you

Similar Threads

  1. [MangosZero] Updated SQL databases
    By LordExeon in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 05-02-2010, 12:01 PM
  2. Naxxramas 80 Update SQL script
    By Iksf in forum WoW EMU General Releases
    Replies: 34
    Last Post: 06-22-2009, 05:04 AM
  3. Handy: Update SQL, List of all the needed SQL updates since Antrix
    By [Shon3m] in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 10-28-2007, 06:21 PM
All times are GMT -5. The time now is 03:12 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search