Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Count the clicks

    I have a site that is full of pictures that people can download. (Wallpapers). What I need is somehow be able to have a page where you can click the link to downlaod the pic. But also on the same page some where near the link have a box that contains the number of times that link have been clicked on. Does anyone know how this can be done?
    "Knowledge Speaks But Wisdom Listens"

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If you are using mysql

    Create a table with 2 columns, Linkid and Clicks.

    You need to edit the link to the download page and make sure there is a ?id=NUMBER on the end, Ill explain later.

    PHP Code:
    <?php

    $db 
    = @mysql_connect('localhost','user','pass') or die(mysql_error());
    @
    mysql_select_db('dbname',$db);

    $getCurrentAmt "SELECT * FROM `new_table_name` WHERE Linkid='".$_GET['id']."';";
    $num = @mysql_query($getCurrentAmt);
    $amt = @mysql_num_rows($num);

    $sql_query "UPDATE `new_table_name`
                           SET `Clicked`= '"
    .($amt+1)."'
                           WHERE Linkid='"
    .$_GET['id']."';";
    @
    mysql_query($sql_query);

    ?>
    This code updates the database. You need each of your images to have an id, and insert all of them into the database. When you link to the download page, make sure you have the id=ImageId after the link ( eg. download.php?id=1 )

    Then to display the amount of times clicked, use this simple function:

    PHP Code:
    <?php

    function getClicks($linkid)
    {
         
    // YOU DONT NEED THIS IF YOU ARE ALREADY CONNECTED TO YOUR DATABASE
         
    $db = @mysql_connect('localhost','user','pass') or die(mysql_error());
         @
    mysql_select_db('dbname',$db);
         
    // YOU DONT NEED THIS IF YOU ARE ALREADY CONNECTED TO YOUR DATABASE


    $que "SELECT * FROM `new_table_name` WHERE Linkid='".$linkid."';";
    $get mysql_query($que);
    $row mysql_fetch_row($get);

    return 
    $row['Clicks'];

    }

    ?>
    You could use the function like this:
    Code:
    $clicks = getClicks(1);
    echo $clicks;

    Hope this helps. If you need it explaining I will help you some more.


  •  

    Posting Permissions

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