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

警告: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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效