Counting total clicks
Posted: Sun Jan 22, 2006 8:53 pm
I have this code which updates the amount of times a tutorial is viewed each month and 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.
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.";
?>Let me know if that is not clear.