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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Incrementing a link count before a redirect

    Hello,

    I have a page of links and I wish to count the number of times these are clicked by incrementing a number in a MySQL database. I have thought about each link leading to the same page which checks against the database which link is clicked, increments it, and then redirects to the other website.

    However, having the URL of the links on my page pointing to this same page will not give the external web pages (my link partners) any value i.e. google will not rank them. I would be selling my link exchanges short. I could do this with a text file but a database would be tidier because I want to use the click through statistics elsewhere in my site.

    How can I achieve this and maintain value for my link exchanges?

    Many thanks.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Using jQuery/Javascript you can have an onclick event that fires off an ajax call to your DB update-- kind of a fire-and-forget update, because the user will be sent off to the link's destination at the same time the ajax is being called.

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts
    i thought ajax would be a solution but wasnt too keen on getting involved in it. Have you got a sample script which does something similar of point me in the right direction so i can adapt something else?

    Thanks

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Shameless plug for jQuery here... using jQuery, ajax calls are one liners. Amazingly simple. jQuery has a learning curve of its own, but once you get used to how the syntax works, it's not bad at all.

    Here's an example of a link that when clicked makes an ajax call and redirects to the link. It's not tested so it may not actually work exactly right, but you'll get the idea of how easy ajax is with jQuery.

    HTML:

    Code:
    <a id="googlelink" href="http://www.google.com">Google</a>
    jQuery code:

    Code:
    $("#googlelink").click(function() {
        $.post("update.php", { linkid: this.id });
    });
    PHP update code (update.php):

    PHP Code:
    if (isset($_POST['linkid'])) {
        
    //update query goes here


  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Fumigator View Post
    Shameless plug for jQuery here... using jQuery, ajax calls are one liners. Amazingly simple. jQuery has a learning curve of its own, but once you get used to how the syntax works, it's not bad at all.
    I'll second that recommendation. jQuery makes using ajax so much simpler. Their documentation is fairly decent too: http://docs.jquery.com/Main_Page
    OracleGuy


  •  

    Posting Permissions

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