just yesterday i finished one site, which provides video watch开发者_开发知识库ing. but now i need to show the number of views of each film. i never wrote such thing, so i don't know what to do.
maybe i must add one field in mysql database, and increase it every time the video opened? but i use flash player, and i can't wrote script onclick of player. so, could you give me an idea... thanks
The best way is probably going to be to just parse your webserver's log and look for when Flash requests the video stream (nightly cron job). I'm guessing you are using a pre-existing Flash video player, where you may not have the ability to modify the Flash to push a server request to update the view count when PLAY is clicked, nor do I recommend it because you might switch to another player or to HTML5 streaming.
As already suggest I also agree, just add a "view_count" to your "video" table and increment it, you can do it in one step with (no need to retrieve, add and update)
UPDATE video SET view_count = view_count + 1
Also keep in mind, if you incrimenting your video count upon loading the video page, make sure to exclude page views from search bots (ex: google) because half or more of your view counts could end up being search bots. You can find a list of search bot browser strings, so you know what to look for here.
I'd create a table called video_views
or something, have it contain the id of the video being viewed. I'd then use Flash's ExternalInterface
functionality to call a JavaScript function which would, in turn, hit a remote URL via ajax to add a new record to video_views
.
I've done this a few times in the past and it's always worked well. You could also just maintain a view_count
value in your videos table and increment that each time a video is viewed.
[Edit]
One argument in favor of tracking each individual view would be the ability to add a timestamp to each record and gain further insight into things like peak traffic times.
Another way to go about it is to pass the web (Apache) Logs through a script real time by using the CustomLog directive as such
CustomLog |/var/www/view_count.php common
This would allow for real time statistics. Not sure if you need those or not.
fetch like below:
$viewd=$results['viewd'];
$viewd+=1;
mysql_query("update user set viewd = '$viewd' where id='1'");
精彩评论