Hi

I'm trying to write a blog application, but I will keep to the part 
where I'm having problems... there will certainly be more problems 
to solve, but I'll meet those when I come to them. :)

The bit I'm trying to work out is how to display the blog entries 
with all the associated comments listed below each blog entry.

I am displaying the most recent blog entry first and want to display 
the associated comments underneath, oldest first.

I have created two tables, blogs and comments.

The comments table has a foreign key called bID which correseponds 
to the bID in the blogs table which is the primary key for that 
table.

Here is my code. I have run two queries. The first selects the rows 
in the blogs table and orders them by the 'timeAdded' column. The 
second query selects the comments where the C.bID = B.bID.

I have nested the second query output (while clause) in the first 
query output (the first while clause).

What happens is the blog entries display as intended, but all the 
comments display under the first blog entry, and not under their 
related blog entries.

Going round in circles here, can anyone help?

Code here...

[Database connection]
$result = mysql_query("SELECT B.bID, B.timeAdded AS Btime, B.title, 
B.entry FROM blogs B ORDER BY B.timeAdded DESC");

      if (!$result) {

          print ("<P>Error performing query: " .
          mysql_error() . "</P>");

      exit();

      }
                 $result2 = mysql_query("SELECT C.timeAdded AS 
Ctime, C.name, C.comment  FROM comments C, blogs B WHERE C.bID = 
B.bID ORDER BY C.timeAdded ASC");

      if (!$result2) {

          print ("<P>Error performing query: " .
          mysql_error() . "</P>");

      exit();

      }
                                  
       while ( $row = mysql_fetch_array($result) ) { ?>
                                  <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 85%; font-weight: bold"><?=$row['title']?></span></td>
                                                          </tr>
                                                          <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 60%"><?=$row['Btime']?></span></td>
                                                          </tr>  
                              <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 75%"><?=$row['entry']?></span></td>
                                                          </tr>
<?php while ( $row = mysql_fetch_array($result2) ) { ?> 
                                  <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 85%; font-weight: bold"><?=$row['name']?></span></td>
                                                          </tr>
                                                          <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 60%"><?=$row['Ctime']?></span></td>
                                                          </tr>  
                              <tr>
                                                           <td><span 
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 75%"><?=$row['comment']?></span></td>
                                                          </tr>
                                                     <?php } } ?>

TIA.

Richard





------------------------ Yahoo! Groups Sponsor --------------------~--> 
1.2 million kids a year are victims of human trafficking. Stop slavery.
http://us.click.yahoo.com/WpTY2A/izNLAA/yQLSAA/CefplB/TM
--------------------------------------------------------------------~-> 

The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to