dongzhao4036 2018-10-18 00:04
浏览 23

正常的SQL语句到Preparedstatement疑难解答

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入