...

View Full Version : Incrementing a link count before a redirect



alex57
03-15-2009, 06:01 PM
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.

Fumigator
03-16-2009, 07:58 AM
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.

alex57
03-16-2009, 03:08 PM
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

Fumigator
03-16-2009, 04:11 PM
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:



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


jQuery code:



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


PHP update code (update.php):



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

oracleguy
03-16-2009, 05:18 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum