Jump to content

Recommended Posts

Hi, I am working on adding to my website, something that will show the view count for a video.  Then I plan on showing the videos with the most views on my homepage.  I know how to get mySQL datebase up and how to send info to and from it, but I don't know what the code for this would be.  I have an id auto int. for the videos, but it's the code that counts the times the play button has been clicked that I am wondering about.  Thanks in advance for the help.

Link to comment
https://forums.phpfreaks.com/topic/73726-most-viewed-videos/
Share on other sites

What I do for my videos site is:

 

Everytime the page for the video is loaded, it adds +1 to the video's total views. If you only want it to increase when the user has actually clicked PLAY then it will take more than php.

 

And for displaying the top viewed vids just do:

 

// Get the video data from the DB

$sql = "SELECT * FROM video_table ORDER BY video_views ASC";

$result = mysql_query($sql) or die (mysql_error());

$row = mysql_fetch_array($result);

 

// Count how many rows (videos) there are selected.

$total_vids = count($row);

 

// Display each one

for ($i=0; $i<$total_vids; $i++)

{

    echo "{$i}. $row['video_title'] <br />";

}

 

Be sure to change your table and column names.

Link to comment
https://forums.phpfreaks.com/topic/73726-most-viewed-videos/#findComment-372023
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.