致命错误:未捕获错误:无法将mysqli_result类型的对象用作数据库数组

时间:2018-09-28 22:53:35

标签: php html mysql

我无法弄清楚这里出了什么问题,我试图显示数据库结果,这给了我这个错误,这是怎么回事?

<?php
$mysqli = new mysqli("localhost","root","","fakultet");
if ($mysqli->error) {
    die("Greska :".$mysqli->error);
}
$upit = "Select * from student WHERE sifra>165";
$rez = mysqli_query($mysqli,$upit);

?>

<html>
<head>
    <title></title>
</head>
<body>
    <table width="600" border="1" cellpadding="1" cellspacing="1">
        <tr>
            <th>BrInd</th>
            <th>Prezime</th>
            <th>Ime</th>
            <th>status</th>
            <th>sifra</th>
        </tr>

        <?php

        while ($kokoš=mysqli_fetch_assoc($rez)) {
            echo "<tr>";
            echo "<td>".$rez['BrInd']."</td>";
            echo "<td>".$rez['Prezime']."</td>";
            echo "<td>".$rez['Ime']."</td>";
            echo "<td>".$rez['status']."</td>";
            echo "<td>".$rez['sifra']."</td>";
            echo "</tr>";
            # code...
        }
?>

</table>
</body>
</html>

我不是专家,我只是想学习它,但这让我很头疼。 提前非常感谢您!

1 个答案:

答案 0 :(得分:2)

您已将结果集中的行提取到名为$kokoš的变量中,因此该变量包含列数据。

while ($kokoš=mysqli_fetch_assoc($rez)) {
    echo "<tr>";
    echo "<td>".$kokoš['BrInd']."</td>";
    echo "<td>".$kokoš['Prezime']."</td>";
    echo "<td>".$kokoš['Ime']."</td>";
    echo "<td>".$kokoš['status']."</td>";
    echo "<td>".$kokoš['sifra']."</td>";
    echo "</tr>";
    # code...
}