Hey guys. I'm building a simple blog and have my data returning from my database in an array. I want to show the comments associated with each blog post but I'm not sure how to organize this in a loop. This is my array:
Array
(
[author] => Administrator
[post] => Testing entry number one
[entry_date] => Fri, 23 Oct 2009
[commenter] => Sally Anderson
[comments] => comment 1 post 1
[comment_date] => October 24th, 2009 at 5:24 AM
[blog_id] => 1
)
Array
(
[author] => Administrator
[post] => Testing entry number two
[entry_date] => Sat, 24 Oct 2009
[commenter] => Sally Anderson
[comments] => comment 1 post 2
[comment_date] => October 24th, 2009 at 5:21 AM
[blog_id] => 2
)
Array
(
[author] => Administrator
[post] => Testing entry number one
[entry_date] => Fri, 23 Oct 2009
[commenter] => Mike
[comments] => comment 2 post 1
[comment_date] => October 24th, 2009 at 5:21 AM
[blog_id] => 1
)
Array
(
[author] => Administrator
[post] => Testing entry number two
[entry_date] => Sat, 24 Oct 2009
[commenter] => Mike
[comments] => comment 2 post 2
[comment_date] => October 24th, 2009 at 5:21 AM
[blog_id] => 2
)
Notice that each post repeats based on the number of comments associated with it. In this particular case this array has 2 comments associated with each post. Could someone please help me write a foreach loop that will output 2 posts with the correct comments for each one?
Thanks!
Maybe I'm not explaining well enough. Here is what I am looking for.
Array
(
[author] => Administrator
[post] => Testing entry number one
[entry_date] => Fri, 23 Oct 2009
[commenter] => Sally Anderson
[comments] =>
**[0] => Array
(
comment 1 post 1
comment 2 post 1
)**
[comment_date] => October 24th, 2009 at 5:24 AM
[blog_id] => 1
)