PDA

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



Tabo
04-29-2007, 08:45 PM
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.



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


It can be PHP or PHP + MYSQL

Thanks

cr0w
04-30-2007, 02:20 AM
Assuming you know how to create the tables & columns correctly, here you go:

In example.php:

<?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:

<?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').')';
?>