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

Link to comment
Share on other sites

<?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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.