0

可能重复:
警告:mysql_fetch_* 期望参数 1 是资源,布尔给定错误

我收到此错误:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given in /Applications/MAMP/htdocs/start-fbook/facebook.php
on line 113

这是代码。当我提交“状态”时,它会保存在我的数据库中,所以那部分没有问题。

<?php 
    //Eerst bouwen we onze applicatie uit zodat ze werkt, ook zonder JavaScript
    include_once("classes/Activity.class.php");
    $activity = new Activity();

    //controleer of er een update wordt verzonden
    if(!empty($_POST['activitymessage']))
    {
        $activity->Text = $_POST['activitymessage'];
        try 
        {
            $activity->Save();
        } 
        catch (Exception $e) 
        {
            $feedback = $e->getMessage();
        }
    }

    //altijd alle laatste activiteiten ophalen
    $recentActivities = $activity->GetRecentActivities();

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IMDBook</title>
<link href="css/reset.css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
body
{
    font-family: "Lucida Grande", Tahoma, Verdana, sans-serif;
}

h1
{
    margin-bottom: 5px;
}

h2
{
    color: #3b5998;
    display: inline;
}

ul
{
    margin-top: 10px;
}

ul li
{
    border-bottom: 1px dotted #fff;
    padding: 15px 5px;
}

#activitymessage
{
    border: 1px solid #bbbbbb;
    padding: 5px;
    width: 280px;
    font-size: 1.1em;
}

div.statusupdates
{
    width: 380px;
    background-color: #ccc;
    padding: 20px;
    margin: 0 auto;
}

#btnSubmit
{
    background-color: #627aac;
    color: #fff;
    font-size: 1.1em;
    border: 1px solid #29447e;
}

div.errors
{
    width: 380px;
    margin: 25px auto;
    background-color: #bd273a;
    -moz-border-radius: 10px;
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 1px #000;
    padding: 20px;
    display:none;
}
</style>
<script type="text/javascript">


</script>
</head>
<body>
<div>
    <div class="errors"></div>

    <form method="post" action="">
        <div class="statusupdates">
        <h1>GoodBytes.be</h1>
        <input type="text" value="What's on your mind?" id="activitymessage" name="activitymessage" />
        <input id="btnSubmit" type="submit" value="Share" />

        <ul id="listupdates">
        <?php 
            if(mysqli_num_rows($recentActivities) > 0)
            {       
                while($singleActivity = mysqli_fetch_assoc($recentActivities))
                {
                    echo "<li><h2>GoodBytes.be</h2> ". $singleActivity['activity_description'] ."</li>";
                }
            }
            else
            {
                echo "<li>Waiting for first status update</li>";    
            }
        ?>
        </ul>

        </div>
    </form>

</div>  
</body>
</html>
4

1 回答 1

1

您应该像这样进行检查:

if($recentActivities !== false) {
    //code here
}

如果查询失败,数据库调用将返回 false。

于 2012-05-02T10:15:05.527 回答