成员函数查询错误

时间:2013-10-10 09:27:33

标签: php object mysqli

我有一个打印多级菜单的代码。但它也向我说: 在行中的非对象上调用成员函数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);
?>

0 个答案:

没有答案