Jump to content

Recommended Posts

How would I use mysql to fetch data from a table and list the top 10 watched movies. The database is "TheFilmGod" and uses "views" as the column for the number of views. Then php would output the top ten watched videos by sending out the page ids. So each row would have "views" and a "page_id" column.

 

So I want the mysql to search and find the top 10 largest numbers in the "views" column send back the "page_id" back. I'm totally confused. Any help on any of the steps is greatly appreciated!

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

First of all you need the name of the table and not the database.. the database name is only relevant for connecting to the database and since you already have records in your db you must have made a db connection - so I'll call you table for table :)

 

"SELECT page_id FROM table ORDER BY views DESC LIMIT 10"

 

The above query will sort your table by views in DESCADING order, which means the largest number first, and then select the page_id from the first 10 records in the newly sorted/ordered tabel.

 

 

Link to comment
https://forums.phpfreaks.com/topic/44711-most-viewed-list/#findComment-217097
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.