TheFilmGod Posted March 28, 2007 Share Posted March 28, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/44711-most-viewed-list/ Share on other sites More sharing options...
Wuhtzu Posted March 28, 2007 Share Posted March 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/44711-most-viewed-list/#findComment-217097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.