More a psudocode question that a php coding question.
I have a blog, on one page it loops through 10 blog posts, so it kinda looks like this:
PHP Code:
$rsEntries = mysql_query("SELECT * FROM blog_entries WHERE id ='1'");
while ($entry=mysql_fetch_array($rsEntries)) { echo ' <div class="blog_header">'.$entry['title'].'</div> <div class="blog_body">'.$entry['body'].'</div> <div class="blog_footer">Posted by '.$entry['user'].' on '.$entry['date'].'</div> '; }
(the SQL isn't done)
Somewhere I want it to say how many comments the post has, and link to a comments page.
Should I query the comments table in every loop?
like SELECT * FROM blog_comments WHERE entry_id ='1' ?
It just seems kinda inefficient to query the database every time in a loop. Is there another way or is this what I should do?
|