0

我有一个代码,它正在打印一个多级菜单。但它也对我说:在非对象上调用成员函数 query() ... 查询是正确的,我已经在另一个文档中对其进行了测试,并且它运行良好。我进行了一些研究,但不幸的是,到目前为止没有任何建议有效:/

代码是:

<?php $mysqli = new mysqli("host", "user" "pass", "db") or die ('Cannot open database'); ?>
<?php
function display_children($parent, $level) {
    global $mysqli;

    $result = $mysqli->query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `medialib_cats` a LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `medialib_cats` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);

    echo "<ul class='nav'>";

    while ($row = $result->fetch_assoc()) {
        if ($row['Count'] > 0) {
            echo "<li><a href='index.php?page=folder.php&fid=" . $row['id'] . "'>" . $row['label'] . "</a>";
            display_children($row['id'], $level + 1);
            echo "</li>";
        } elseif ($row['Count']==0) {
            echo "<li><a href='index.php?page=folder.php&fid=" . $row['id'] . "'>" . $row['label'] . "</a></li>";
        } else;
    }

    echo "</ul>";
}
display_children(0, 1);
?>
4

0 回答 0