How do I calculate the number of views?

just yesterday I finished one site that provides video viewing. but now I need to show the number of views of each movie. I've never written such a thing, so I don't know what to do.


Maybe I should add one field to the mysql database and increment it every time the video opens? but i am using flash player and i cant write player onclick script. so can you give me an idea ... thanks

+2


a source to share


4 answers


The best way would probably be to just analyze your web server log and look for when Flash requests a video stream (nightly cron job). I am assuming you are using a pre-existing Flash video player where you may not be able to modify Flash to send a server request to update the view count when PLAY is clicked and I do not recommend it because you might switch to another player or HTML5 stream.

As I said, I also agree, just add "view_count" to your "video" table and enlarge it, you can do it in one step (no need to extract, add and update)



UPDATE video SET view_count = view_count + 1

      

Also keep in mind that if you are uploading a video while loading a video page, be sure to exclude page views from crawlers (like Google), because half or more of your views could be crawlers. You can find a list of browser search strings, so you know what to look for here .

+2


a source


I would create a table called video_views

or whatever, let it contain the id of the video being watched. I then used a Flash function ExternalInterface

to call a JavaScript function, which in turn would remove the remote url via ajax in order to add a new entry to video_views

.

I've done this several times in the past and it has always worked well. You can also just store the value view_count

in your video table and increase it each time you watch the video.



[change]

One of the arguments in favor of tracking each individual submission would be the ability to add a timestamp to each entry and gain a deeper understanding of things like peak traffic times.

+1


a source


Another way is to stream web logs (Apache) in realtime script using CustomLog directive as such

CustomLog |/var/www/view_count.php common

This will allow you to get statistics in real time. Not sure if you need these or not.

0


a source


select as below:

    $viewd=$results['viewd'];
    $viewd+=1;
    mysql_query("update user set viewd = '$viewd' where id='1'");

      

0


a source







All Articles