coupon code statistics coupon code statistics php php

coupon code statistics


I assume you have coupons stored in some table with code, description, etc, etc. add num_used column to it and increment it every time the coupon is used. This way you can still insert the coupon into orders if need be but you don't need to do counts. You simply check how many times it was already used when you load your coupon info. I assume you check validity by coupon code anyway so throw another one in for number of times.


You can "attach" the coupon code to one order.

Example (for you mysql orders table):order ABC use coupon "Coupon1"order BCD use coupon "Coupon1"

And then, yes you can use a function like this one:

function getCouponUsage($a_couponCode){  $res = mysql_query("SELECT couponCode FROM orders WHERE coupon = '$a_couponCode'") or die(mysql_error());  return mysql_num_rows($res);}

This function will return an integer. Just compare with your limit.

You can also set a hit counter. Let say the coupon can be used 500 times, when someone use the coupon you remove one so the total would be 499 (the coupon can be used 499 from now).