.Darkman Posted April 25, 2007 Share Posted April 25, 2007 Hello Everybody, I need some help displaying top content from my database. For eg, I have an article system. I have two tables in the DB. One is articles : containing article_id, title, and the article columns. Other is the rating table containing article_id and a rating (btw 0-5). Now what i want to do is display the Top 10 articles on the basis of their rating. How do i do it ? I have thought in many ways. But none worked. Please Help Thank You Link to comment https://forums.phpfreaks.com/topic/48548-top-content/ Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 $sql = "SELECT articles.article_id as id, articles.title, articles.article, rating.article_id, rating.rating FROM `articles` JOIN `rating` ON (articles.article_id = rating.article_id) ORDER BY `rating.rating` DESC LIMIT 0, 10"; anybody wanna back me up on this one... Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237685 Share on other sites More sharing options...
.Darkman Posted April 25, 2007 Author Share Posted April 25, 2007 Ok that helped a little. But the rating table does not contain just one rating per article. It contains many ratings - one by each user for each article. Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237687 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 $sql = "SELECT rating.article_id as id, AVG(rating.rating) as article_rating, articles.article_id, article.title, article.article FROM rating JOIN `articles` ON (rating.article_id = articles.article_id) GROUP BY id ORDER BY `rating` DESC LIMIT 0,10"; $result = mysql_query($sql) or die(mysql_error()); while($row .... Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237693 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 i'm not sure but give it a whirl. should give u some ideas. Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237695 Share on other sites More sharing options...
.Darkman Posted April 25, 2007 Author Share Posted April 25, 2007 Okay, that may be complicated. How about on a del.icio.us site ? A link is saved. In the links table, the link and user_id are stored. Top links are shown on the basis of how many people have saved it. (i.e) a link with most occurrences in the links table will be on top and with least occurrences will be on bottom. How shall this be done ? Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237712 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 $sql = "SELECT COUNT(link) as count, user_id FROM `links` GROUP BY `user_id` ORDER BY `count` DESC LIMIT 0,10"; $result = mysql_query($sql) or die(mysql_error()); while($row .... im new to grouping and counting and avgs in mysql, but thatSHOULD work... Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237718 Share on other sites More sharing options...
.Darkman Posted April 25, 2007 Author Share Posted April 25, 2007 I will try this later today. Thanks, Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237722 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 yep Link to comment https://forums.phpfreaks.com/topic/48548-top-content/#findComment-237729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.