Hello. If you have a mysql db then we are in luck. Here is how I do it. It will be a little long but it is well worth it.
First: Make a table... Create table hits (
hits_id INT NOT NULL AUTO_INCREMENT,
title_of_page TEXT,
num_hits_of_page TEXT,
Primay Key(hits_id));
That should make a table.
Second: You will need to insert your pages you have. This could be some manual typing. Lets assume you have 3 pages. About Us , Pictures , Contact. Insert all three pages. "Insert Into hits Values(Null,'About Us','0')"; This will say that your page name is About Us and your hits are set at 0. Do that for the other pages. Also your title_of_page could be set to the product id or something along those lines. Either way will work.
Third: On your homepage you can have this up there
<?php
$db = mysql_connect("localhost","username","password");
mysql_select_db("dbname", $db);
$sql = "select * from hits order by num_hits_of_page LIMIT 5 DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "Top 5 hit pages!";
printf("<a href='link'>%s</a>",$row["title_of_page"]);
}
?>
That will take everything you have in Hits, order them by num_hits_of_page, Limit them to 5, and then Place in Descending order. You can also have ASC == Ascending.
Fourth: You will need to of course have your pages updating and rewriting themselves in the database. This is accomplished by Update function. You can use this script placed in the the header or something.
<?php
$db = mysql_connect("localhost","username","password");
mysql_select_db("dbname", $db);
$sql = "Select * from hits where title_of_page='$definethetitle'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$id = $row["hits_id"];
$oldtotal = $row["num_hits_of_page"];
$newtotal = $oldtotal + 1;
$super = "UPDATE hits SET num_hits_of_page='$newtotal' where hits_id='$id'";
mysql_query($super);
}
?>
There now you are done! Sit back and watch the hits rise. The things I told you here have not been tested nor did I ever say that they will be 100% correct. Though I think I pasted the source code correctly. My memory fails sometimes.
Wow that wasnt that hard. There are tons of other ways of doing this. But this is my system that I like best. If you have any other questions then please let me know. I am always willing to help. Catch me on AIM though. Chads2k2. Thanks!
Chad
A.K.A. Ziggs