Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-23-2009, 03:14 PM blog with comments
Extreme Talker

Posts: 176
Trades: 0
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?
Skeddles is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-23-2009, 05:36 PM Re: blog with comments
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
The best method to use would be to store the amount of comments within the blog_entries table.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-23-2009, 06:47 PM Re: blog with comments
Extreme Talker

Posts: 176
Trades: 0
Good idea, thanks.
Skeddles is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to blog with comments
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16407 seconds with 12 queries