freelance84 Posted August 20, 2010 Share Posted August 20, 2010 Hi, I have a promotional_offers table, one of the fields is a counting field (to count the number of times the promo code has been used) I can't have the count field to be auto increment, what is the most efficient way of incrementing the value? Would it be: //get current count $query = mysql_query("SELECT count FROM promotional_offers WHERE code = '$code'") $query_row = mysql_fetch_row($query); $new_count = $query_row[0] + 1; //update count with new value $query_insert = mysql_query("UPDATE promotional_offers SET count='$new_count' WHERE code='$code'"); Or is there a way of doing this all in mysql? Quote Link to comment https://forums.phpfreaks.com/topic/211273-incrementing-a-count-field-for-promo-codes/ Share on other sites More sharing options...
trq Posted August 20, 2010 Share Posted August 20, 2010 You can simply do.... UPDATE tbl SET fld = fld + 1 WHERE fld = 45; Quote Link to comment https://forums.phpfreaks.com/topic/211273-incrementing-a-count-field-for-promo-codes/#findComment-1101604 Share on other sites More sharing options...
freelance84 Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks thorpe, I thought there would something like that, my book doesn't cover it. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/211273-incrementing-a-count-field-for-promo-codes/#findComment-1101606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.