php - Mysql Select value then update -


basically i'm trying turn id out of table, after value returned needs incremented 1. after 10 increments, resets 0;

so want do similar can't seem working:

update `gan` set `turn` = (select `turn` `gan` `gan_id`='$gan_id') + 1 

i haven't figured out how check if value 10 reset 0;

so need happen, in php mysql query, current turn returned gan_id pass in , increment after value has been returned.

i've tried running 2 separate queries i'm running issue multiple users getting same turn.

mysql_query("set autocommit = 0"); mysql_query("start transaction"); $result = mysql_query("select turn gan gan_id = $gan_id update"); $turn = mysql_fetch_array($result); $somenewval = $turn == 10 ? 0 : $turn + 1; $resupdate = mysql_query("update gan set turn = $somenewval gan_id = $gan_id"); mysql_query("set autocommit = 1"); mysql_query("commit"); 

no? need select update if wanna handle concurrency.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -