Page 1 of 1

Hits per day script

Posted: Tue Mar 22, 2005 8:10 pm
by stofolies
I currently have a script that counts the hits per day I get. It uses the MySQL database to store all the info. What I want to do is edit this script so that at the end of the day it will record the total hits for that day in another table in the database so that I can go back and view my hits per day from previous days. I have no clue how to even begin this task, I am a total PHP newbie, I just found this script on evilwalrus I believe.

If anyone knows how I can accomplish this then any help would be greatly appreciated. Thanks.

Code: Select all

<?php

mysql_connect('localhost','user','pass');//db host info

mysql_select_db('dbname');//db name

$date10 = date("j/m/Y"); //today's date

//this inserts new records

$daily1 = mysql_query("INSERT INTO `q_daily_count` (`ID`, `date`) VALUES (Null, '$date10')");

//this deletes the old records

$delete = mysql_query("DELETE FROM q_daily_count WHERE date <> '$date10'");

//this shows how many hits you have got in a day. just copy the function to a page where you want to 
//show the count, make sure you type in correct username, password and datbase name.
//copy from here
$show = mysql_query("select * FROM q_daily_count");
$get = @mysql_num_rows($show);
$get = number_format($get);
echo $get;

?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Mar 22, 2005 8:35 pm
by feyd
First off, I'd suggest converting all the dates to MySQL standard format: Y-m-d

What I would do is insert the totals for a day when the first of a new day happens. You can figure out if it's a new day based simply on doing a select against the log table to count the current dates entries. If any are found, it's not the first of the day. If none are found, do a count on the previous day and insert it to your other table.


Moved to PHP - Code.