How Can I Count Clicks on Links to See Which Ones are Most Popular?

Discussion in 'PHP' started by Masterful, Sep 8, 2008.

  1. #1
    Any help on this matter will be rewarded with reputation points. :)

    Say I had 20 links on a page. How can I count which ones have been clicked on the most? Then, how can I select the 5 most popular?
     
    Masterful, Sep 8, 2008 IP
  2. wmcoder

    wmcoder Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There's a number of ways but the simplest would be to create a table and track which link is clicked as well as incrementing the number of clicks..

    Then to select the 5 most popular you could use an sql statement like

    SELECT link FROM tbl_links ORDER BY clicks DESC LIMIT 5

    to grab the 5 most clicked links
     
    wmcoder, Sep 8, 2008 IP
  3. darkblue

    darkblue Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you will have to make a table and each page will be redirected through any other page e.g. redirect.php?url=http://www.google.com and htis page will save details in database, then you can fetch those details and see..
     
    darkblue, Sep 8, 2008 IP
  4. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #4
    OK. I understand the MySQL SELECT part, but not how the clicks are going to be added to the table.

    Let's say that all of my links are in a table. First, I will have to add another column to the table and call it something like Clicks, right? Then, how do I get each click to be added to the respective link's row? When someone clicks on the link, they're just going to be directed to wherever the URL points. How am I going to add the click to the table? :confused:

    Sorry, Darkblue, but I don't understand what you mean. Note that I am but a mere blundering novice at PHP, having just started learning this week! :eek:
     
    Masterful, Sep 8, 2008 IP
  5. ariefdisolo

    ariefdisolo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes you are right. You need a PHP script to insert or increase the Clicks when user clicking on the link.

    Link_ID Link_URL Clicks
    1 http://google.com 1

    Then your link URL can be like this:
    http://yourdomain.com/goto.php?link_id=1

    In your goto.php you just need to add an SQL statement to increase the Clicks and redirect user to the URL.
     
    ariefdisolo, Sep 8, 2008 IP
  6. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Google analytics and other stats tools is OK.
    analytics the stats report and find out what are the visitor interested in and which are most clicked.
     
    justinlorder, Sep 8, 2008 IP
  7. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #7
    So, let me get this straight . . .

    I need to create a page for every individual URL. When visitors click on a URL, they will be taken to its respective page, where a script will log the click and add it to the table, before redirecting the visitor to the original destination. Is that correct?

    If so, I'm afraid it's a bit too impractical a method. I will eventually have 1,000s of URLs in my database. I can't create a seperate "log and redirect" page for each one.
     
    Masterful, Sep 8, 2008 IP
  8. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #8
    You can have a javascript to track the clicks on the links...
     
    Freewebspace, Sep 8, 2008 IP
  9. Dollar

    Dollar Active Member

    Messages:
    2,598
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Dollar, Sep 9, 2008 IP
  10. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #10
    Thanks for the help, guys! :)
     
    Masterful, Sep 9, 2008 IP