I have a forum that students are posting in. If the student responds to the main post, the postId is set to 0. If a student replies to another student's post, the postId is set to the replyId of the student's original post.
I am trying to write some PHP that will essentially create a new table for each post, with the exception of if a postid is set to a reply Id, then create a new row in that table.
I have the SQL laid out in SQLFiddle which can be found here:
http://sqlfiddle.com/#!2/611e2d/5
Using this example, what I'm looking for is replyid one to be put in a new html table, with response ID 3 in a new row underneath that. Then with ReplyId 2, would create a new html table.
This is just a basic threaded forum view of responses.
Thank you!
[code]
$i = 0;
$aR = 0;
$currentPost = '';
if(mysql_num_rows($getResponses) > 0)
{
while($respData = mysql_fetch_array($getResponses))
{
if(($respData['postId'] != $currentPost))
{
if($i!=0)
{
echo '</table><br /><br />';
}
echo '<table width = "875px" cellspacing = "0" cellpadding = "0" border = "0">';
$i=0;
}
$currentPost = $respData['postId'];
$color_A = 'class="altRow1"';
$color_B = 'class="altRow2"';
$altRowColor = ($aR % 2) ? $color_A : $color_B;
$studentName = getStudents($respData['userId']);
$studentName = explode(" ", $studentName);
$studentFirstName = $studentName[0];
echo '<tr ' . $altRowColor . '>
<td align="center" width = "225px" class="forumTopic"><img src="images/'.getStudentPics($respData['userId']).'.png" /><br />Posted By ' . getStudents($respData['userId']) . '<br />on '.date("m/d/Y h:i a", strtotime($respData['responseDate'])) . '</td>
<td width = "650px" class="forumTopic">' . $respData['replyText'] . '</td>
</tr>
<tr ' . $altRowColor . '>
<td class="forumTopic" colspan = "2" align="center"><span class="topicLinkStyle"><a href="postResponse.php?postId='.$respData['replyId'].'&topic='.$topicId.'" class="iframe750x600">Reply to '.$studentFirstName .'</a></span></td>
</tr>';
$i++;
$aR++;
}
echo '</table><br /><br />';
}