Link to home
Start Free TrialLog in
Avatar of pingeyeg
pingeyeg

asked on

Replies are not going in the place

Can anybody tell me how to make this happen?  I have a bit of code that I can't seem to make it do what I want with as little code as possible.  The page that I am working on is http://www.brannonglover.com.  Basically what I am trying to do is have one subject and comment per multiple replies.  I have the one comment per line working just fine, but the multiple replies do not seem to stay under their own individual comment.  This is my code so far:

<table width="100%" cellpadding="0" cellspacing="0">
<tr><td class="title">
<?php
while($row = mysql_fetch_array($sql_title)) {
                  $strTitle = $row['strTitle'];

echo $strTitle;
?>
</td><td class="menu">
<?= menu; ?>
</td></tr>
<tr><td>
<table width="100%" cellpading="0" cellspacing="0">
<?php
while($row = mysql_fetch_array($sql_comment)) {
                  $intPost_ID = $row['intPost_ID'];
                  $strSubject = $row['strSubject'];
                  $strComment = $row['strComment'];
                  $strName = $row['strName'];
                  $strTime = $row['strTime'];

echo "<tr><td class=\"title_body\">";
echo "<div class=\"subject\">" . subject . $strSubject . " &nbsp;&nbsp;&nbsp;<span style=\"color: #828283\"> (" . comment . $strName . ") </span></div>";
?>
<div style="margin-top: 10px">
<span class="credited"><?= credited . $strTime ?></span>
<div class="comment">
<?=
$strComment . " " . " &nbsp;<a href=\"reply.php?Posted_Comment=" . $intPost_ID . "\" style=\"text-decoration: none; color: #5d7091\">Reply</a>" ?>
</div>
<div style="margin-top: 10px">
<?php
while($row = mysql_fetch_array($sql_reply)) {
                  $intReply_ID = $row['intReply_ID'];
                  $strTime = $row['strTime'];
                  $strReply = $row['strReply'];
                  $strReply_Name = $row['strReply_Name'];
                  $strSubject = $row['$strSubject'];
?>
<span class="credited"><?= credited . $strTime . " (" . comment . $strReply_Name . ")" ?></span>
<div class="comment">
<?=
$strReply . " " . " &nbsp;<a href=\"reply.php?Reply_Comment=" . $intReply_ID . "\" style=\"text-decoration: none; color: #5d7091\">Reply</a>" ?></div>
<?php } ?>
</div></div>
<?php } } ?>
<div style="margin-top: 40px; margin-bottom: 5px" align="center">
<table class="comment" cellpadding="0" cellspacing="0">
<tr><form action="insert_subject.php" method="post">
<input type="hidden" name="strTime" value="<?= date("F j, Y, g:i a") ?>"><td>
<?= subject ?>
</td></tr>
<tr><td>
<input type="text" name="strSubject" size="30">
</td></tr>
<tr><td>
Comment:
</td></tr>
<tr><td>
<textarea rows="5" cols="50" name="strComment"></textarea>
</td></tr>
<tr><td>
Name:
</td></tr>
<tr><td>
<input type="text" name="strName" size="20">
</td></tr>
<tr><td align="center">
<input type="submit" value="Submit Entry">
</td></form></tr>
</table>
</td></tr>
</table>
Avatar of Rurne
Rurne
Flag of United States of America image

First and foremost, run your HTML through Tidy.  You've got some mismatched div and form elements that need cleaning.

That said, seeing as everything is classed as "comment", I can't tell if there are any actual replies in your source or not.  Either you need to apply a different CSS class to your replies, or you need to supply some.  If you do indeed have them, check the differences between the result sets in $sql_comment and $sql_reply.
Avatar of pingeyeg
pingeyeg

ASKER

I have gone back over my code and everything seems to be working well.  I even tried testing is by placing the subject above each reply to see where it is being referred to and the on that should be under a different subject is under the same as the others.
ummm... i know that one of the "stengths" of PHP is that you CAN include it in HTML, but...
I don't see here how you are actually getting the data, which i'm assuming is off in an include file somewhere...

additionally - what is the data structure you are getting the information from?

if you wanted to do something like this it might almost be better to get it all, and include the original subject in all the lines and then:

$result = mysql_query("some query to get all of the data")

if($result !== false)
{
    $prevPostId= null;

    while( $row = mysql_fetch_assoc($result) )
    {
            if( $row['intPost_ID'] != $prevPostId )
            {
                // write out the post heading
                $prevPostId = $row['intPost_ID'];
            }

            // write out the reply body
    }
}


you'll be getting more info back from your data source in one shot, but it will make your life easier as it will be a single query, and a single loop.  Because I can't see your query or your data structure in this post, and i don't want to type all the output code this is as far as i can go for a suggestion..
Thanks you for the reply.  Just to let you know the following are my sql statements:

$sql_comment = mysql_query("SELECT DISTINCT tblPosts.intPost_ID, tblPosts.strSubject, tblPosts.strComment, tblPosts.strName, tblPosts.strTime FROM tblPosts")
            or die(mysql_error());
            
            $sql_reply = mysql_query("SELECT tblReplies.intReply_ID, tblPosts.intPost_ID, tblReplies.strTime, tblReplies.strReply, tblReplies.strReply_Name, tblPosts.strSubject, tblReplies.strSubject FROM tblPosts, tblReplies WHERE tblPosts.strSubject = tblReplies.strSubject ORDER BY tblReplies.strTime desc")
            or die(mysql_error());
            
            $sql_title = mysql_query("SELECT strTitle FROM tblTitle") or die(mysql_error());
ASKER CERTIFIED SOLUTION
Avatar of ebosscher
ebosscher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is what I have from your code.  Not sure if I missed something, but right now it doesn't work.

<table width="100%" cellpading="0" cellspacing="0">
<?php
if($postResult = mysql_query($sql_comment))
{
    while($postRow = mysql_fetch_assoc($postResult))
    {

echo "<tr><td class=\"title_body\">";
echo "<div class=\"subject\">" . subject . $strSubject . " &nbsp;&nbsp;&nbsp;<span style=\"color: #828283\"> (" . comment . $strName . ") </span></div>";
?>
<div style="margin-top: 10px">
<span class="credited"><?= credited . $strTime ?></span>
<div class="comment">
<?=
$strComment . " " . " &nbsp;<a href=\"reply.php?Posted_Comment=" . $intPost_ID . "\" style=\"text-decoration: none; color: #5d7091\">Reply</a>" ?>
</div>
<div style="margin-top: 10px">
<?php
while($row = mysql_fetch_array($sql_reply)) {
                  $intReply_ID = $row['intReply_ID'];
                  $strTime = $row['strTime'];
                  $strReply = $row['strReply'];
                  $strReply_Name = $row['strReply_Name'];
                  $strSubject = $row['strSubject'];
?>
<span class="credited"><?= credited . $strTime . " (" . comment . $strReply_Name . ")" ?></span>
<div class="reply">
<?=
$replySql = "SELECT strTime, strReply, strReply_Name, strSubject FROM tblReplies WHERE intPost_ID = " . $postRow['intPost_ID'];
        if($replyResult = mysql_query($replySql))
        {
            while($replyRow = mysql_fetch_assoc($replyResult))
            {
$strReply . " " . " &nbsp;<a href=\"reply.php?Reply_Comment=" . $intReply_ID . "\" style=\"text-decoration: none; color: #5d7091\">Reply</a>";
?></div>
<?php } ?>
</div></div>
<?php } } } } ?>
I tried copying and pasting your example, but that didn't work either so I tried to integrate yours with mine.
What doesn't make much sense to me is the fact that I have the sql statement putting the subjects from both tables together so that the reply should be going under the correct heading.
ok, in your integrated version that you posted you're still using the variables $strSubject for the subject header.  you'll need to replace those with the corrosponding $rowvariable['columnname'] variables

so for the subject instead of using $strSubject you'll have to use $postRow['strSubject']

i'm guessing you're not seeing the error messages when you run the form, you're just getting the output with no data, right?

also get rid of this: <?php
while($row = mysql_fetch_array($sql_reply)) {
                  $intReply_ID = $row['intReply_ID'];
                  $strTime = $row['strTime'];
                  $strReply = $row['strReply'];
                  $strReply_Name = $row['strReply_Name'];
                  $strSubject = $row['strSubject'];
?>


it's processing all of the rows in an odd place..
you know what... i tried fixing up your php, and you lost me... I've been programming for going on 9 years now, and you lost me  :o).  Not to fear, we can do this together still.

if you could write out your HTML for one subject with two comments followed by a second subject with two comments and just put the names of the database fields you need in given places inside of some markup

for instance if you want the post id from the post table to show up somewhere in the HTML write

**tblPost.intPost_ID**

where you want to see it.  that will visually demark where you want to have the value.
what we're designing here is an HTML template, and then we can insert the PHP code into the HTML.

before you post your HTML please make sure that it works visually for you, so that when we insert the PHP it will give you the same look as if it were straight HTML.

an example of what i'm talking about would be if we wanted to create a table that had the results of the tblPosts query in it the HTML template would look like this:

<table cellspacing="0" cellpadding="0" border="1">
<tr>
    <th>ID</th>
    <th>Subject</th>
    <th>Comment</th>
    <th>Name</th>
    <th>Time</th>
<tr>
    <td>**tblPosts.intPost_ID**</td>
    <td>**tblPosts.strSubject**</td>
    <td>**tblPosts.strComment**</td>
    <td>**tblPosts.strName**</td>
    <td>**tblPosts.strTime**</td>
</tr>
</table>

from that template we would be able to insert the proper variables to do the processing into the HTML.
I hope this is what you are looking for.  I may have gone too far with though.

<table cellspacing="0" cellpadding="0" border="0">
<tr><td>
<div class="subject">
Subject: **tblPosts.strSubject** &nbsp;&nbsp;<span style="color: #828283"> (Comment from: **tblPosts.strName**) </span></div>
<div style="margin-top: 10px">
<span class="credited">Created on: **tblPosts.strTime**</span>
<div class="comment">
**tblPosts.strComment** &nbsp;<a href="reply.php?Posted_Comment=**tblPosts.intPost_ID**" style="text-decoration: none; color: #5d7091">Reply</a>"
</div>
<div style="margin-top: 10px">
<span class="credited">Created on: **tblPosts.strTime** ("Comment from: **tblPosts.strName**")</span>
<div class="reply">
**tblReplies.strReply** &nbsp;<a href="reply.php?Reply_Comment=**tblReplies.intReply_ID** style="text-decoration: none; color: #5d7091">Reply</a>
</div>
</div></div>
<div style="margin-top: 40px; margin-bottom: 5px" align="center">
<table class="comment" cellpadding="0" cellspacing="0">
<tr><form action="insert_subject.php" method="post">
<input type="hidden" name="strTime" value="<?= date("F j, Y, g:i a") ?>"><td>
Subject:
</td></tr>
<tr><td>
<input type="text" name="strSubject" size="30">
</td></tr>
<tr><td>
Comment:
</td></tr>
<tr><td>
<textarea rows="5" cols="50" name="strComment"></textarea>
</td></tr>
<tr><td>
Name:
</td></tr>
<tr><td>
<input type="text" name="strName" size="20">
</td></tr>
<tr><td align="center">
<input type="submit" value="Submit Entry">
</td></form></tr>
</table>
</td></tr>
</table>
This is what I have done so far.  It definitely changed things a little, but still not there:

<?php
if($postResult = mysql_query($sql_comment))
{
      while($postRow = mysql_fetch_assoc($postResult))
      {
?>
<tr><td class="title_body">
<div class="subject">
Subject: <?= $postRow['strSubject'] ?> &nbsp;&nbsp;<span style="color: #828283"> (Comment from: <?= $postRow['strName'] ?>) </span></div>
<div style="margin-top: 10px">
<span class="credited">Created on: <?= $postRow['strTime'] ?></span>
<div class="comment">
<?= $postRow['strComment'] ?> &nbsp;<a href="reply.php?Posted_Comment=<?= $postRow['intPost_ID'] ?>" style="text-decoration: none; color: #5d7091">Reply</a>
</div>
<div style="margin-top: 10px">
<?php
if($replyResult = mysql_query($sql_reply))
{
      while($replyRow = mysql_fetch_array($replyResult))
      {
?>
<span class="credited">Created on: <?= $replyRow['strTime'] ?> (Comment from: <?= $replyRow['strReply_Name'] ?>) <?= $replyRow['strSubject'] ?></span>
<div class="reply">
<?= $replyRow['strReply'] ?> &nbsp;<a href="reply.php?Reply_Comment=<?= $replyRow['intReply_ID'] ?>" style="text-decoration: none; color: #5d7091">Reply</a>
</div>
</div></div>
<?php } } } } ?>
Have you had a chance to look at my reply?
sorry, I missed the replies, I wasn't being very faithful with checking my Experts Exchange emails of late
I'll have a quick look and post another response, even though you marked this answered
I believe this should do it for you.  I have replaced one of the post sections (the second one) with a reply section so that you'll actually see the reply information in the header, rather than the post information a second time.  (hope that made sense)

<?
$sql_reply = "SELECT strTime, strReply, strReply_Name, strSubject FROM tblReplies WHERE intPost_ID = " . $postRow['intPost_ID'];
?>

<table cellspacing="0" cellpadding="0" border="0">
<tr><td>

<?
if($postResutl = mysql_query($sql_comment))
{
    while($postRow = mysql_fetch_assoc($postResult))
    {
?>

      <div class="subject">
      Subject: <?=$postRow['strSubject']?> &nbsp;&nbsp;<span style="color: #828283"> (Comment from: <?=$postRow['strName']?>) </span></div>
      <div style="margin-top: 10px">
      <span class="credited">Created on: <?=$postRow['strTime'}?></span>
      <div class="comment">
      <?=$postRow['strComment']?> &nbsp;<a href="reply.php?Posted_Comment=<?=$postRow['intPost_ID']?>" style="text-decoration: none; color: #5d7091">Reply</a>"
      </div>
<?
        $replySql = "SELECT strTime, strReply, strReply_Name, strSubject FROM tblReplies WHERE intPost_ID = " . $postRow['intPost_ID'];
        if($replyResult = mysql_query($replySql))
        {
            while($replyRow = mysql_fetch_assoc($replyResult))
            {
?>

            <div style="margin-top: 10px">
            <span class="credited">Created on: <?=$replyRow['strTime']?> ("Comment from: <?=$replyRow['strName']?>")</span>
            <div class="reply">
            <?=$replyRow['strReply']?> &nbsp;<a href="reply.php?Reply_Comment=<?=$replyRow['intReply_ID']?> style="text-decoration: none; color: #5d7091">Reply</a>
            </div>
            </div>
<?
            }
        }
?>

      </div>
<?
    }
}
?>

<div style="margin-top: 40px; margin-bottom: 5px" align="center">
<table class="comment" cellpadding="0" cellspacing="0">
<tr><form action="insert_subject.php" method="post">
<input type="hidden" name="strTime" value="<?= date("F j, Y, g:i a") ?>"><td>
Subject:
</td></tr>
<tr><td>
<input type="text" name="strSubject" size="30">
</td></tr>
<tr><td>
Comment:
</td></tr>
<tr><td>
<textarea rows="5" cols="50" name="strComment"></textarea>
</td></tr>
<tr><td>
Name:
</td></tr>
<tr><td>
<input type="text" name="strName" size="20">
</td></tr>
<tr><td align="center">
<input type="submit" value="Submit Entry">
</td></form></tr>
</table>
</td></tr>
</table>