Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    199
    Thanks
    78
    Thanked 5 Times in 5 Posts

    Count Views by IP

    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:

    Code:
    video_ID (unique)
    url
    title
    uploaded by
    date
    Views
    The second table with the following fields

    Code:
    video_ID
    IP

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

    Code:
    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.

  • #2
    New Coder
    Join Date
    Apr 2011
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    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

  • Users who have thanked craig101 for this post:

    conware (05-25-2011)

  • #3

  • Users who have thanked gvre for this post:

    conware (05-25-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •