This displays all comments or questions from a student population.
The reply from a course director need to be displayed just underneath its corrosponding question.
Comment table
$cid
Reply table
$rid
$cid
Each reply will have a matching cid from the comment table.
I have to figure out the proper loop and why I was getting all 4 replies for a single comment.
function index() {
include_once("header.php");
global $AllowableHTML, $user, $cookie, $anonymous, $db, $language;
$op = ($_POST['op']);
$result = $db->sql_query("SELECT * FROM comment_queue");
$num_rows = mysql_num_rows($result);
Opentable();
echo '<table width="99%" border="1"><tr><td width="500">';
echo '<div class="title">';
echo'<tr><p><center>Welcome to the Muddy Waters Questions and Answers. <br >';
echo'All submitted questions and comments are placed in waiting status until answered.</center><br />';
echo'</tr></table><br />';
echo '</div>';
echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF'] ."\">\n";
echo '<table width="99%" border="0"><tr><td width="50%">';
echo '<input name="submit" type="submit" value="Post a Question" />';
echo '<input name="op" type="hidden" value="comment" /></td>';
//[ <a href="admin/login.php">'$num_rows'</a> ]
echo "<center>Questions Waiting [ <a href=\"admin/login.php\">$num_rows</a> ]\n";
echo "</div>";
//echo '<td width ="50%">$num_rows</td></tr>';
echo '<hr>';
echo '</form>';
Closetable();
$result = $db->sql_query('SELECT * FROM comments cm
JOIN course cs
ON cm.course_id = cs.course_id
ORDER BY time');
while ($row = $db->sql_fetchrow($result)) {
$cid = $row['cid'];
$time = $row['time'];
$name = 'Annonymous';
$comment_text = stripslashes($row['comment_text']);
$course_fullname = stripslashes($row['course_fullname']);
$title = stripslashes($row['title']);
echo '<div class="content">';
OpenTable();
echo "<table width=\"99%\" border=\"1\" CELLPADDING=\"10\" CELLSPACING=\"10\"><tr><td width=\"500\">";
echo "<p><b>Course: $course_fullname</b><br />";
echo "<p>Title: $title<br />";
echo "<p>By $name On $time</p>";
echo "</td></tr>";
echo "<tr><td><div class=\"content\">$comment_text</div></td></tr>";
echo "<br>";
$result = $db->sql_query('SELECT * FROM reply r JOIN comments c WHERE c.cid= r.cid');
while ($row = $db->sql_fetchrow($result)) {
$reply_text = $row['reply_text'];
$rid = intval($row['rid']);
$time = $row['time'];
$formatdate = date("M j, Y g: i A",strtotime("$time"));
$name = "Muddy";
echo "<table width=\"89%\" align =\"center\" BGCOLOR=\"#EFEFEF\" border=\"1\" CELLPADDING=\"10\" CELLSPACING=\"10\"><tr><td width=\"450\">";
echo "<p><b>Reply</b><br />By $name On $time</p>";
echo "</td></tr>";
echo '<tr><td><div class="answer">'.$reply_text.'</div></td></tr></table><br /><br />';
echo "</div>";
echo '<hr>';
}
}
echo"</table><br /><br />";
echo '<br>';
CloseTable();
echo '</div>';
include("footer.php");
}
I also have another way of doing this by using another function and passing the $cid.
function displayReply($cid) {
global $AllowableHTML, $user, $cookie, $anonymous, $db, $language;
$result = $db->sql_query('SELECT * FROM reply r JOIN comments c WHERE r.cid= c.cid');
while ($row = $db->sql_fetchrow($result)) {
$reply_text = $row['reply_text'];
$rid = intval($row['rid']);
$time = $row['time'];
$formatdate = date("M j, Y g: i A",strtotime("$time"));
$name = "Muddy";
OpenTable();
echo "<table width=\"99%\" BGCOLOR=\"#EFEFEF\" border=\"1\" CELLPADDING=\"10\" CELLSPACING=\"10\"><tr><td width=\"500\">";
echo "<p><b>Reply</b><br />By $name On $time</p>";
echo "</td></tr>";
echo '<tr><td><div class="answer">'.$reply_text.'</div></td></tr></table><br /><br />';
echo "</div>";
echo '<hr>';
CloseTable();
}
Not quite working as planned but I'm almost ready to demo this.
Just need to figure out why I was getting all my replies displaying under the one comment.