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
https://forums.phpfreaks.com/topic/92201-auto_increment-on-non-key-fields/
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 ?

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.