With PHP & MYSQL, I need a scalable way to show a few comments for each post just like in facebook. For all the posts in my application I need to print the most recent comments beneath the post. The problem is that I dont want to put a SQL query in a loop and have to run 20 SQL queries per page. Is there one SQL query that I can use to get the 2 most recent comments for each post that I get from the posts table.
Asked
Active
Viewed 297 times
0
-
1See: http://stackoverflow.com/questions/6788099/mysql-two-of-every-set – Ariel Jul 27 '11 at 09:35
1 Answers
0
I believe you can retrieve all the comments using one query and then store them in an array. You can then iterate over the array to organize them.

Ren
- 1,111
- 5
- 15
- 24

Dvid Silva
- 1,110
- 13
- 25