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.

Recommended Answers

All 3 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.