Welcome Guest, Not a member yet? Register   Sign In
How to loop though a list of blog entries and all their comments on the same page
#1

[eluser]Unknown[/eluser]
Hi folks!

I have a simple database structure like this:

Code:
entries table
+----+-----------+------------+-----------+------+
| id | date_time | post_title | post_slug | body |
+----+-----------+------------+-----------+------+

comments table
+----+-----------+----------+------+--------+
| id | date_time | entry_id | body | author |
+----+-----------+----------+------+--------+

I am in a situation where I need to loop through all my etnries and all the comments on the same page. How do I go on and do this in the best possible way (performance and maintainability)

Do I need to first loop through all my entries and then within that loop get all it's comments and loop through them? That means alot of queries to the database. Is there a better way?

The desired output looks like this:
Code:
Entry #1
  Comment #1
  Comment #2
Entry #2
  Comment #1
  Comment #2
  Comment #3
Entry #3
Entry #4
  Comment #1

I hope this is not a duplicate of other posts but I searched for a long time and couldn't find anything...

Thanks!


Messages In This Thread
How to loop though a list of blog entries and all their comments on the same page - by El Forum - 11-27-2010, 03:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB