Video Counter dependant on number of plays

57 Views Asked by At

I am building a website where I display multiple videos from various users. I have tried to create a hit counter which increases dependant on the number of views but the counter stays as 1, updates on all videos as well as fails to update the DB. My script looks like

$video_id = $run['videoid'];        
//## Get views
$getViews = mysql_query("SELECT `hits` FROM `views` WHERE `id` = {$video_id}");
if(mysql_num_rows($getViews)) {
  $result = mysql_fetch_assoc($getViews);
  $videoViews = $result['hits']+1; 
} else {
  $videoViews = 1;
}


mysql_query("INSERT INTO `views` (`id`) VALUES ({$video_id}) ON DUPLICATE KEY UPDATE hits = hits+1");

echo 'Total Views: '.number_format($videoViews);

Iv been racking my brain for a few days now, has anyone got any ideas?

0

There are 0 best solutions below