dongyihao9887 2015-12-08 10:12
浏览 74
已采纳

警告:mysqli_fetch_array()要求参数1为mysqli_result,[复制]中给出布尔值

This question already has an answer here:

I have a problem here is my page which i getting the error from

<?php
        // retrive post
        include('config.php');
        include ('function.php');
        dbConnect();

        $query = mysqli_query($GLOBALS["___mysqli_ston"], 
            'SELECT *
            FROM post
            WHERE post_id = 1');
        $row = mysqli_fetch_array($query);
    ?>

and the error is showing this line

$row = mysqli_fetch_array($query);

and the second error is in this code

<div class="comment-block">
         <?php while($comment = mysqli_fetch_array($comment_query)): ?>
            <div class="comment-item">
                <div class="comment-avatar">
                    <img src="<?php echo avatar($comment['mail']) ?>" alt="avatar">
                </div>
                <div class="comment-post">
                    <h3><?php echo $comment['name'] ?> <span>said....</span></h3>
                    <p><?php echo $comment['comment']?></p>
                </div>
            </div>
        <?php endwhile?> 
        </div>

error line is this

 <?php while($comment = mysqli_fetch_array($comment_query)): ?>     

pleas help me i am very new to mysqli

</div>
  • 写回答

2条回答 默认 最新

  • matlabmann 2015-12-08 10:15
    关注

    There are a lot of possible reasons. Main reason: The query failed. You may have tried to access a table, a column, that is not existing.

    Use die($query) and try it out in phpMyAdmin and see if it really executes.

    Alternatively using mysqli_error($conn_object) will also contain some information about what happened.

    Also, while using the loop, try to give in this format:

    while (false != ($comment = mysqli_fetch_array($comment_query))
    

    Snippet

    A typical database query, I would write this way:

    <?php
        // Connect to the MySQL Server
        $conn = mysqli_connect("localhost", "root", "password", "database") or die("Cannot Connect to MySQL Server. Error: " . mysqli_connect_error());
    
        // Once connection is established, build a query
        $query = "SELECT * FROM `users`";
        // Execute the query and store it in the results
        $results = mysqli_query($conn, $query);
    
        // Only continue if there are rows in your result.
        if (mysqli_num_rows($results))
            // Loop through the results, but don't assign directly inside while
            while (false != ($data = mysqli_fetch_array($results)))
                // Display data using the column name
                echo "User: " . $data["User"];
        // Handle the empty scenario
        else
            echo "No users found.";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化