I’m developing a comment system and thought I was done with it until I was told I had to display all the damn comments instead of just the last one posted (you know how bosses can be, always changing their minds at the very last second).
Anyways, part of it is with php and the other part is jquery. Jquery code: //gets comments for initial secret
var quid = "quid=<?=$ans['quid']?>";
$.post("inc/comments_system.php", quid, function(data) {
if(data.number > 0) {
$("#comm").html("<p><a href='#'>"+data.number+"</a></p>");
$("#cbox").show();
$("#cdisplay").show().html(data.comment);
$("#quid").attr("value", data.quid);
} else {
$("#comm").html("<p><a href='#'>"+data.number+"</a></p>");
$("#quid").attr("value", data.quid);
}
}, "json");
and the php part [php] default:
$q = mysql_query(“SELECT COUNT(oid) as num, comment, username, oid, createdon FROM comments WHERE oid = $_POST[quid] ORDER BY createdon”) or die(mysql_error());
if(mysql_num_rows($q) != 0) {
while($ans = mysql_fetch_assoc($q)) {
$username .= "<br /><div style='font-style: italic; text-align: right;'> -$ans[username]@ ".date('m-d-y G:i.s', strtotime($ans['createdon']))."</div></div>";
$comment .= "<div style='width: 95%; margin: 0 auto'>".$ans['comment'].$username;
$num = $ans['num'];
}
$ret = array("number" => $num, "comment" => stripslashes($comment), "quid" => $_POST['quid']);
} else {
$ret = array("number" => 0, "quid" => $_POST['quid']);
}
break;
}
echo json_encode($ret);[/php]
I thought by putting it in a loop, it would create a long string like a loop normally would, but it just seems content on displaying last comment posted. My only other thought would be to use a foreach loop, but that seems messy and not needed to me. Any ideas?