troubleshooting Question

Two ways of doing things ?

Avatar of SaLz
SaLz asked on
PHP
9 Comments1 Solution250 ViewsLast Modified:
Hi guys,
well I'm posting this in new thread as i said :)

As some of you might know, I'm making a download hit counter for two .exe files. In stats i want to see how many times each file has been downloaded each day ( in correct date format: day.month.year ), also i want a total number of downloads for each file, as you can see below, and a total downloads of both files.

File 1:  
20.8.2005 - 20 downloads
19.8.2005 - 12 downloads
Total downloads of File 1: 32
File 2:
20.8.2005 - 30 downloads
19.8.2005 - 16 downloads
Total downloads of File 2: 46)

Total downloads of both files: 78


-----------------------------------------------------------------------------------------------
There are two ways of counting ( or more, feel free to post below :)

1st way: $insert_query="insert into DownloadHits values($fileID,'".$fileName."','".date('Y-m-d')."')";
// adding 1 record for each hit
------------
or 2nd way, something ive been working on:
// check if currentDate matches today's date, if not update it
if ( $currentDate <> date('Y-m-d') ) {
$currentDate = date('Y-m-d');
$result = mysql_query("UPDATE currentDate ...
// insert a new record with new date and add a hit to it
$Date = date('Y-m-d');
$result = mysql_query("INSERT INTO HitCounter SET
fileID = 1,
Date='$Date',
Hits=+1
");
// else update the hits where date is today and add 1 hit to it
} else {
$result = mysql_query("UPDATE HitCounter SET Hits=+1 WHERE Date='".date('Y-m-d')."')"; }
-----------------------------------------------------------------------------------------------------------------
Which method is better, or are there any better ones ?

And how can I do what I asked above ?

Thank you guys for your time :)
Sal
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros