?
Solved

Replies are not going in the place

Posted on 2007-07-25
15
Medium Priority
?
178 Views
Last Modified: 2007-08-12
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>
0
Comment
Question by:pingeyeg
  • 8
  • 6
15 Comments
 
LVL 9

Expert Comment

by:Rurne
ID: 19569108
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.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19569972
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.
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19571154
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..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:pingeyeg
ID: 19571174
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());
0
 
LVL 6

Accepted Solution

by:
ebosscher earned 2000 total points
ID: 19571731
ok, then what i suggested won't work.  I'm assuming there are no issues with the title, so i'l leave that alone and just focus on the subject / reply issue.  your posts query looks fine because you want all of them, but you're going to need to do a bunch of subqueries to match up replies to posts (or a lot of looping in the application)

so do this:

1.  get your information from table posts
2.  start looping through your posts and do the following:
      2.1 write out the subject information
      2.2 create a query to get all replies for the subject
      2.3 start looping through all of your replies and do the following:
            2.3.1 write out the reply information
      2.3 write a spacer (so that the subjects and replies don't get mashed together)


i would recommend writing the SQL for the reply lookup as follows:

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

that will get you only the replies for the current post you're looping through... otherwise it's going to be a mashup of all of the replies for all of the posts.

note: you will need to change the names of the result rows so they don't match (they do in your current code)

if($postResutl = mysql_query($sql_comment))
{
    while($postRow = mysql_fetch_assoc($postResult))
    {
        // write your subject to the page here

        $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))
            {
                // write your reply to the screen here
            }
        }

        // if the css doesn't handle it write some whitespace to the screen here
    }
}
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19574422
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 } } } } ?>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19574432
I tried copying and pasting your example, but that didn't work either so I tried to integrate yours with mine.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19574854
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.
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19576690
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..
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19576830
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.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19584657
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>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19584928
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 } } } } ?>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19592097
Have you had a chance to look at my reply?
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19680613
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
0
 
LVL 6

Expert Comment

by:ebosscher
ID: 19680644
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>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question