Page 1 of 1

Counting total clicks

Posted: Sun Jan 22, 2006 8:53 pm
by Mr Tech
I have this code which updates the amount of times a tutorial is viewed each month and in total...

Code: Select all

<?php
// Current month & year
$month = date('M', time());
$year = date('Y', time());

// Check if month & year exist
$check = mysql_num_rows(mysql_query("select * from clicks where month='$month' and year='$year' and id='$id'"));
if ($check > 0) {
mysql_query("update clicks set tclicks = tclicks + 1 where month='$month' and year='$year' and id='$id'");
} else {
mysql_query("insert into clicks values($month,$year,$id,'1')");
}

// Show total clicks
$totalclicks = mysql_fetch_array(mysql_query("select tclicks from clicks where id='$id'"));
$monthclicks = mysql_fetch_array(mysql_query("select tclicks from clicks where month='$month' and year='$year' and id='$id'"));

echo "This tutorial has been viewed $monthclicks[tclicks] times this month and $totalclicks[tclicks] in total.";
?>
Basically I have to withdraw the total clicks from each month and add them all together. How do I do this?

Let me know if that is not clear.

Posted: Sun Jan 22, 2006 8:59 pm
by d3ad1ysp0rk
SELECT sum(tclicks) FROM clicks WHERE year = $year