Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli_num_rows()要求参数1为mysqli_结果_Php_Mysql - Fatal编程技术网

Php mysqli_num_rows()要求参数1为mysqli_结果

Php mysqli_num_rows()要求参数1为mysqli_结果,php,mysql,Php,Mysql,可能重复: 我收到这个错误: 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

可能重复:

我收到这个错误:

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>

IMDBook
身体
{
字体系列:“Lucida Grande”,Tahoma,Verdana,无衬线;
}
h1
{
边缘底部:5px;
}
氢
{
颜色:#3b5998;
显示:内联;
}
保险商实验室
{
边缘顶部:10px;
}
ulli
{
边框底部:1px点#fff;
填充:15px 5px;
}
#活动消息
{
边框:1px实心#bbbbbb;
填充物:5px;
宽度:280px;
字体大小:1.1米;
}
分区状态更新
{
宽度:380px;
背景色:#ccc;
填充:20px;
保证金:0自动;
}
#btnSubmit
{
背景色:#627aac;
颜色:#fff;
字体大小:1.1米;
边框:1px实心#29447e;
}
部门错误
{
宽度:380px;
保证金:25像素自动;
背景色:#bd273a;
-moz边界半径:10px;
颜色:白色;
字体大小:粗体;
文本阴影:1px 1px 1px#000;
填充:20px;
显示:无;
}
古德比

您应该进行如下检查:

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

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

什么是
$activity->GetRecentActivities()的代码?这真的是一个
mysql\u query()
结果吗?下次请去掉代码中对问题不重要的部分!