I have written a little script to count the downloads on my site, but there is just one little thing:
I'm going to make a script that counts the downloads for each day and file, but my question is:
How do I add all downloads for a file into one integer? Should I first get out all the clicks from the table, and then add them together or what?!
Well, here's my first click counter script:
<?php
$host = "localhost";
$user = "my_user";
$pass = "my_pass";
$db = "my_db";
$connect = mysql_connect($host,$user,$pass);
if(!$connect)
die(mysql_error());
$select = mysql_select_db($db);
if(!$select)
die(mysql_error());
$get = mysql_query("SELECT * FROM downloads WHERE id='$id'");
if(!$get)
die(mysql_error());
$row = mysql_fetch_assoc($get);
if(!$row)
die(mysql_error());
$row[clicks]++;
$add = mysql_query("UPDATE downloads SET clicks='$row[clicks]' WHERE id='$id'");
if(!$add)
die(mysql_error());
header("Location: $row[link]");
$close = mysql_close($connect);
?>
The $id variable is set in the url.