我無法找到我的函數沒有得到所有結果的原因。當我轉到頁面查看評論時,我只能看到最令人憎惡的一個。如果我然後刪除該評論,則顯示下一個最新評論。我確定這件事很簡單,我沒有注意到。
function getComments($inPostID=null)
{
$commentArray = array();
if (!empty($inPostID))
{
//echo " Get comments for the post with the postID of ". $inPostID;
$stmt = db::connect()->prepare("SELECT * FROM Comments WHERE postID = ? ORDER BY commentDate DESC");
$stmt->bind_param('i', $inPostID);
$stmt->execute();
$stmt->bind_result($commentID, $postID, $userID, $commentDate, $commentContent);
while($stmt->fetch())
{
echo"HI ";
$thisComment = new ViewComment($commentID, $postID, $userID, $commentDate, $commentContent);
array_push($commentArray, $thisComment);
}
$stmt->close();
}
return $commentArray;
}
「HI」會回覆多少次?你確定那個特定的postID有多個評論嗎? – 2012-01-17 05:07:02
你檢查了什麼'$ stmt-> execute'產生了嗎? – Sterex 2012-01-17 05:09:08
只有一次,我把它放在那裏進行測試。是的,我敢肯定。我在數據庫上檢查了它,當我刪除了最新的帖子評論時,它提出了該帖子的下一個最新評論。 – 2012-01-17 05:09:57