How to make a click counter for a button

Discussion in 'PHP' started by madsbjerrepedersen, Feb 19, 2009.

  1. #1
    Hi

    I have a problem. I have a button on my website, I want it to counts how many times it has been clicked and display it under it. fx

    <button here>

    This button has been clicked 2746 times.

    I allready have a coded button with a function, which it must keep.

    Mads Pedersen
     
    madsbjerrepedersen, Feb 19, 2009 IP
  2. Scripten

    Scripten Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, if you want it only php you should redirect it to another page, which inserts data into the database. And the other should be easy :)
     
    Scripten, Feb 19, 2009 IP
  3. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #3
    the code is onclick="javascript:countclick();"

    and the code for countclick() is:
    function countclick()
    {
    var c=new Image();
    img.src="/counter.php";
    }
     
    buldozerceto, Feb 19, 2009 IP
  4. Macky99

    Macky99 Banned

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi, I too feel that its the simplest way. In case you need more help then visit w3schools.com.
    Take care.
     
    Macky99, Feb 19, 2009 IP
  5. NadeemJaz

    NadeemJaz Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If your sticking it in a database or a txt file then you'll need some php. Then have a div under the button and update that with innerHTML through JavaScript (if your using ajax - if your posting it back then get PHP to update the number).
     
    NadeemJaz, Feb 20, 2009 IP