View Full Version : Php show how many times a link has been pressed, then show it next to the link
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
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').')';
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.