I can’t find the reason why my function is not getting all the results. When I go to the page to view the comment I only see the most resent one. If I then delete that comment the next newest comment appears. I’m sure it is something simple that I have not noticed.
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;
}
I have figured it out. I was opening a bind statement and then in the ViewComment() function opening another bind statement to get further info from other tables. The fix was to store the bindResults into a array that will be populated by the while and then close that bind statement. Then loop through the amount of results the the while gives in a for loop that calls the ViewComment() with the pramitors being the array from the bindResults array.
Code is below.