Jump to content

auto_increment on non-key fields?


br3nn4n

Recommended Posts

I'm working on a poll script that uses mysql to store the amount of votes each option has. I need it so that it updates the column corresponding to the which option the user picked (which I know how to do), but is there an EASY way (cue: auto_increment) to just add one to whatever number was already there?

 

If not, I'm resigned to having to get the value in the database, do the +1 math, and then UPDATE it to the db.

 

It just seems like it should be easier...like...well, auto_increment lol

 

Thanks!!

Link to comment
Share on other sites

oh wow...okay so you can actually do that? I was thinking that might work but didn't try it.

 

So the syntax would be something like:

 

mysql_query("UPDATE poll SET `votechoice1` = '$userchoice' + 1 WHERE pollnumber = '$thisisthepollnumbervariable'")

 

Is that were the + 1 would go? Or would it be inside the 's ?

Link to comment
Share on other sites

Yes, that's where the add one would go, however, I'm not sure what your $userchoice holds as a value.

 

Based on your update shown, it would be like this:

 

UPDATE poll SET `votechoice1` = `votechoice1` + 1 WHERE ...

 

But I have a feeling that's not what you want or talking about.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.