I've been trying (to no end) to convert the following normal SQLi statement & after hours of trying I'm still not able to see where I'm going wrong. The statement is as follows:
$get_comments = mysqli_query($con, "SELECT * FROM blog_post_comments WHERE post_id='$post_id' AND removed='no' ORDER BY id ASC");
$count = mysqli_num_rows($get_comments);
if ($count != 0) {
while($comment = mysqli_fetch_array($get_comments)) {
$comment_body = $comment['post_body'];
$posted_to = $comment['posted_to'];
$posted_by = $comment['posted_by'];
$date_added = $comment['date_added'];
$removed = $comment['removed'];
$blog_comment_id = $comment['id'];
etc... }
Here is the latest version of what I have for the prepared statement:
$no = 'no';
$get_comments = mysqli_prepare($con, "SELECT * FROM blog_post_comments WHERE post_id=? AND removed=? ORDER BY id ASC");
$get_comments->bind_param('is', $post_id, $no);
$get_comments->execute();
$result = $get_comments->get_result();
$count = $result->num_rows;
$get_comments->free_result();
if ($count != 0) {
while($comment = $result->fetch_assoc()) {
$comment_body = $comment['post_body'];
$posted_to = $comment['posted_to'];
$posted_by = $comment['posted_by'];
$date_added = $comment['date_added'];
$removed = $comment['removed'];
$blog_comment_id = $comment['id'];
etc... }
Can anyone see if I'm missing something here? In the second statement, I'm not getting an error, but I'm also not loading any posts to display.