我正在为我的网站开发自己的自定义论坛,由于某种原因,代码只返回一行。论坛上有两个“帖子”,当回显此功能的结果时,只返回最新的帖子。
function displayTopics($tid)
{
$sql = "SELECT message_body, poster FROM thread_messages WHERE threadID = :tid";
$que = $this->db->prepare($sql);
$que->bindParam(':tid', $tid);
try{
$que->execute();
while($row = $que->fetch(PDO::FETCH_OBJ))
{
$username = $this->getUsername($row->poster);
$html = "<div class='message'>
<div class='userInfo'>
<img width='50' height='50' />
{$username}
</div>
<div class='body'>
{$row->message_body}
</div>
</div>";
}
}catch(PDOException $e){}
$html .=
"<form action='reply.php' method='post'><input type='hidden' name='tid' value='{$tid}'>".
"<textarea name='replybody'>Reply...</textarea>".
"<input type='submit' value='reply'>".
"</form>";
return $html;
}
答案 0 :(得分:0)
我搞砸了,我的坏。循环应该看起来像这样
while($row = $que->fetch(PDO::FETCH_OBJ))
{
$username = $this->getUsername($row->poster);
$html .= "<div class='message'>
<div class='userInfo'>
<img width='50' height='50' />
{$username}
</div>
<div class='body'>
{$row->message_body}
</div>
</div>";
}
我重写了$ Html变量。