How to make Link counters?

Discussion in 'PHP' started by Asimina, Sep 29, 2008.

  1. #1
    how do you create a counter that counts how many times a link have been clicked and show it below the Link?

    example:

    http:www .yahoo.com
    (120clicks!)

    i think it's with a php script..
    Thanks.
     
    Asimina, Sep 29, 2008 IP
  2. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    this file is out .php

    <?php
    
    // Connects to your Database
    mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
    mysql_select_db("Database_Name") or die(mysql_error());
    
    //Adds to the click count for a particular link
    mysql_query("UPDATE table_name SET out = out + 1 WHERE ID = $id")or die(mysql_error());
    
    //Retrieves information
    $data = mysql_query("SELECT * FROM table_name WHERE ID = $id") or die(mysql_error());
    $info = mysql_fetch_array($data);
    
    //redirects them to the link they clicked
    header( "Location:" .$info['URL'] );
    ?>
    PHP:
    and your url in your href would be out.php?id=14

    something like that anyway
     
    cornetofreak, Sep 30, 2008 IP