0

Hello, my website is created almost intirely in php, its dynamic and we have everything working under mysql database. It has printable cuppons for free, the coupons are inside a form, everything works perfectly. Now im trying to find a (php preferably) script that will count how many times that "print coupon" button has been clicked so i know how much of them have been printed. it can be by inserting it (the amount of clicks) in a database table. i believe it is called a Button Hit counter, but since it already has an action, 'cause it prints, i dont know to make it so it does BOTH, print and count how many have been printed.

4
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by JorgeM
0

I am thinking of that button is using JS to print out the discount code.
It could be used with AJAX to count clicks and save it to the DB table too.

0

AJAX can be easily integrated into this solution. Just a few lines of javascript code, or even less if you are already using jQuery.

You can have this button do both as Tpojka suggests. It can be as simple as...

<span id="counter"></span>

$.ajax(
    {
         url:"counter.php",success:function(result)
         {
              // do something with the result
              // such as update your counter
              // on the page.  For example...
              $('#counter').html = result; 
         }
    });

on the counter.php page, just connect to your DB and increment the value that you are storing by one. Read the updated value and return it back to the ajax request. Then client side, take this value and update your counter.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.