猿问

想做产品过滤但我收到错误

我正在做产品过滤器应用程序,但出现此错误


致命错误:未捕获错误:调用未定义的方法 mysqli_stmt::fetchAll()


这是我的代码:


 <div class="list-group">

                    <h3>Grupe</h3>

                    <div style="height: 180px; overflow-y: auto; overflow-x: hidden;">

                    <?php

                    include_once("dbconfig.php");

                    $query = "SELECT DISTINCT(grupa) FROM slike  ORDER BY podgrupa DESC";

                    $statement = $mysqli->prepare($query);

                    $statement->execute();

                    $result = $statement->fetchAll();

                    foreach($result as $row)

                    {

                    ?>

                    <div class="list-group-item checkbox">

                        <label><input type="checkbox" class="common_selector brand" value="<?php echo $row['grupa']; ?>"  > <?php echo $row['grupa']; ?></label>

                    </div>

                    <?php

                    }


                    ?>


<!DOCTYPE html>

<html>

<head>

    <title></title>

</head>

<body>

    <?php

$host="localhost";

$port=3306;

$socket="";

$user="root";

$password="";

$dbname="slikezasajt";


$mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket)

    or die ('Could not connect to the database server' . mysqli_connect_error());


//$mysqli->close();

?>

</body>

</html>

上面是我的 dbconfig 文件。


狐的传说
浏览 142回答 2
2回答

Smart猫小萌

使用以下代码更新您的代码:&nbsp;<div class="list-group">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h3>Grupe</h3>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div style="height: 180px; overflow-y: auto; overflow-x: hidden;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include_once("dbconfig.php");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $query = "SELECT DISTINCT(grupa) FROM slike&nbsp; ORDER BY podgrupa DESC";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $statement = $mysqli->prepare($query);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $statement->execute();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result = $statement->fetchAll(PDO::FETCH_ASSOC);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach($result as $rows =>$row)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="list-group-item checkbox">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label><input type="checkbox" class="common_selector brand" value="<?php echo $row['grupa']; ?>"&nbsp; > <?php echo $row['grupa']; ?></label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?><!DOCTYPE html><html><head>&nbsp; &nbsp; <title></title></head><body>&nbsp; &nbsp; <?php$host="localhost";$port=3306;$socket="";$user="root";$password="";$dbname="slikezasajt";$mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket)&nbsp; &nbsp; or die ('Could not connect to the database server' . mysqli_connect_error());//$mysqli->close();?></body></html>

开满天机

试试这个代码。我已经测试过了,它在我的本地笔记本电脑上工作。&nbsp; <?php&nbsp; &nbsp; $host="localhost";&nbsp; &nbsp; $port=3306;&nbsp; &nbsp; $socket="";&nbsp; &nbsp; $user="root";&nbsp; &nbsp; $password="";&nbsp; &nbsp; $dbname="slikezasajt";&nbsp; &nbsp;&nbsp; &nbsp; $mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket)&nbsp; &nbsp; &nbsp; &nbsp; or die ('Could not connect to the database server' . mysqli_connect_error());&nbsp; &nbsp; &nbsp; $query = "SELECT DISTINCT(grupa) FROM slike&nbsp; ORDER BY podgrupa DESC";&nbsp; &nbsp; &nbsp; $statement = $mysqli->query($query);&nbsp; &nbsp; ?><!DOCTYPE html><html><head>&nbsp; &nbsp; <title></title></head><body>&nbsp; &nbsp;<div class="list-group">&nbsp; &nbsp; <h3>Grupe</h3>&nbsp; &nbsp; <div style="height: 180px; overflow-y: auto; overflow-x: hidden;">&nbsp; &nbsp; <?php&nbsp; &nbsp;while($row = $statement->fetch_assoc())&nbsp; &nbsp; {&nbsp; &nbsp; ?>&nbsp; &nbsp; <div class="list-group-item checkbox">&nbsp; &nbsp; &nbsp; &nbsp; <label><input type="checkbox" class="common_selector brand" value="<?php echo $row['grupa']; ?>"&nbsp; > <?php echo $row['grupa']; ?></label>&nbsp; &nbsp; </div>&nbsp; &nbsp; <?php&nbsp; &nbsp; }&nbsp; &nbsp; ?></body></html>
随时随地看视频慕课网APP
我要回答