Thread: How can count visits?
Results 1 to 2 of 2
01-26-2005, 05:15 AM #1
How can count visits?
I’m having table visits:
| date | ip |
| 2005-01-24 15:03:05 | 0.0.0.1 |
| 2005-01-24 15:15:05 | 0.0.0.1 |
| 2005-01-24 15:45:05 | 0.0.0.1 |
| 2005-01-24 15:03:15 | 0.0.0.2 |
| 2005-01-24 15:33:05 | 0.0.0.2 |
I want count how the visits were made. A timeout period of new visit is 30 minutes.
Result will be:
| date | visits |
| 2005-01 | 2 |
01-26-2005, 10:19 AM #2
Just to make sure I understand you, you already have the visits table, and its been recording data. You just want to know how to make a meaningful report?
The simple way is
SELECT * FROM visits ORDER BY ip
To make this more meaningful, its going to get complicated.
We will assume a day at first. If you want a report spanning more days, you can add a loop afterwards that loops thru a range of days.
lets say 2005-01-01
it selects all results for 2005-01-01, order by time.
You then go through each result. Take the timestamp, take the IP. Add it to an array with a third value in the array of 1 (visits)
For the next result, compare the IP. Is it the same? If it is, then check the time. If the time is more than 30 minutes later, add +1 to the (visits) value of the array for that IP. If less than 30 minutes, then ignore and move on to the next.
Now, once this process finishes, if you then print out the array, you will have your data above in the format you wanted.
I was going to actually provide code, but its pretty complicated and I think you will be better off creating the actual nuts and bolts yourself. That way, you will get it exactly the way you want it.If one of our members helps you, please click the icon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?