致命错误:未捕获错误:在C:\ xampp中调用boolean上的成员函数fetch_assoc()

时间:2018-03-19 16:20:01

标签: php sql mysqli

运行下面的代码时出现上述错误。在更改某些行之前,它完全正常工作,例如变量$appcode。之前,在我做一些更改之前,我手动定义了$appcode值。然后我尝试通过从我在上一页中定义的$_SESSION变量中获取值来自动化该值。

以下是代码,错误陈述位于$res之后的变量$appcode

<?php
    session_start();
    $con= mysqli_connect("localhost", "root", "");
    mysqli_select_db($con, "coba3thesis");

    $appcode = $_SESSION['appcode'];
    $res = mysqli_query($con, "SELECT * FROM section4 WHERE mod(pictureID, 2) = 0 NOT IN (SELECT pictureID FROM temp_pic WHERE appcode = $appcode) ORDER BY RAND() LIMIT 1");

    while($row= $res->fetch_assoc()){
        $hetero = $row['hetero'];
        $homo = $row['homo'];
        $pedo = $row['pedo'];
        $picID = $row['pictureID'];
        $picname = $row['picturename'];
        $desc = $row['description'];
    }
?>

感谢您的帮助,感谢您。

1 个答案:

答案 0 :(得分:0)

while($row= mysqli_fetch_assoc($res)){
        $hetero = $row['hetero'];
        $homo = $row['homo'];
        $pedo = $row['pedo'];
        $picID = $row['pictureID'];
        $picname = $row['picturename'];
        $desc = $row['description'];
    }