Advanced Search

Results 1 to 2 of 2

Thread: Php show how many times a link has been pressed, then show it next to the link

  1. #1
    Join Date
    Feb 2007
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Php show how many times a link has been pressed, then show it next to the link

    Hey, Can anyone give me or point me to a cut and paste.

    I need a php script that counts the number of times a link has been pressed, e.g.


    Code:
    <a href="example.html">Example</a> (X hits)

    It can be PHP or PHP + MYSQL

    Thanks

  2. #2
    Join Date
    Apr 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Assuming you know how to create the tables & columns correctly, here you go:

    In example.php:
    Code:
    <?php
    mysql_connect("mysql_server","username","password");
    mysql_select_db("database_name");
    
    mysql_query("UPDATE link_clicks SET example = example+1") or die(mysql_error());
    ?>
    Where you want it to display:
    Code:
    <?php
    mysql_connect("mysql_server","username","password");
    mysql_select_db("database_name");
    
    $getClicks=mysql_query("SELECT example_link FROM link_clicks");
    $showClicks=mysql_fetch_assoc($getClicks);
    
    echo '('.$showClicks['example_link'].' hit'.(($showClicks['example_link']==1) ? '' : 's').')';
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •