Jump to content

Top Content


.Darkman

Recommended Posts

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

$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

 

$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

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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.