...

View Full Version : Count Views by IP



conware
05-15-2011, 05:11 PM
Hi everyone, I was wondering what the best approach would be to count
views in my database by IP.
I have a video table where i want to count how maney times a video has
been watched. Now my question how should I make my tables, currently
ive done it like this:


video_ID (unique)
url
title
uploaded by
date
Views

The second table with the following fields


video_ID
IP


So basically the IP table will be filled with IP addresses like so:


video_ID IP
1 127.0.0.1
2 127.0.0.1
1 192.168.0.1
3 192.168.0.4


But is there not a better way in doing this? thanks for any replies.

craig101
05-17-2011, 10:58 PM
I don't think there is a better way of doing, by storing just the ID, means you are not storing any unneeded data, so i don't think you can get it any better than that, as that is a very good way of doing it.

The only thing you might want to consider is having a 'Times' field, so if a user watches the video more than once (i assume this is all done in PHP?)

SELECT * FROM TABLE WHERE video_ID = $video_ID AND IP = $IP
if row = 1
$times = $row['time']
$times ++
UPDATE TIMES WHERE video_ID = $video_ID AND IP = $IP
ELSE
INSERT INTO TABLE video_ID, IP, '1'

now if you do that way, you won't be able to do the row count to get the true figure but:

SELECT * FROM TABLE WHERE video_ID = $video_ID
WHILE (QRY)
$times = $row['times']
$total = $total + $times

gvre
05-18-2011, 02:29 PM
You can add a date field in second table in order to be able to retrieve views/date, views/date/ip, views/date/video_id.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum