Basically,
I have two tables, one with Some posts on and another for comments, what I am trying to do is create a page with the most popular posts, I will render popular posts depending on how many comments it has.
Here’s the query I have so far
mysql_query("SELECT * FROM posts JOIN comments ON posts.id = comments.content_id ORDER BY count('comments.id') LIMIT 10");
But the count() is messing it up, could anyone help me? THANKS!
If you have an aggregate function, such as
COUNT(*), you should include aGROUP BYclause:Also, since you want to return posts with the most comments, you’ll want to sort by the count in descending order (highest to lowest).