Jump to content

Visitor Counter and Adding together column data


jonnyw6969

Recommended Posts

Hi there,

 

Could someone please help me im completely stuck and not even sure if what im trying to do can be done.

 

Ok first off im trying to code a sessioned visitor counter for my website.

That bit hasnt been a problem. Ive created a simple table with 2 feilds.

1) count_id

2) count

And that seems to work great, just adding 1 everytime someone new visits.

 

What i want to do and what seems to have worked well is add a date columb to the table.

When someone visits my site on a new day it creates another row with the new date and then adds 1 to the count of the new date. This now gives me daily stats.

 

I have a admin panel to my website which show me these stats.

 

This is where the problem occurs. I can show the stats of the present day ok but i want to show how many people have visited in the last 7 days.

 

Im assumming i need to add together the count column of the last 7 rows.

This is where i need help.

 

Please someone help

 

Regards

Jon

<?php

$query = mysql_query("SELECT SUM(count) FROM table ORDER BY date DESC LIMIT 7") or die(mysql_error());

list($visits) = mysql_fetch_row($query);

echo "{$visits} visits in the last week.";

?>

 

I'm not sure if I ordered the date field the right way round. I think I got it right though - give it a go :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.