我有一个生成分类菜单的函数。
我要做的是在一个ul中对两个类别进行分组。
问题是almos已修复,但我得到一个空ul(见图片)。
我该怎么解决?

 function categorie($tab){
    global $mysql;
    $return = "";
    $categorie = $mysql->select(sprintf("SELECT * FROM categorii WHERE tab = '%d'", $tab));

    if($mysql->countRows() > 0){
        $i = 0;
            $return .= "<ul class=\"group\">\n";
                foreach ($categorie as $cat) {
                    if($i % 2 == 0){
                        $return .= "</ul><ul class=\"group\">";
                    }

                    $return .= "\t<li>\n";
                    $return .= "\t\t<ul>\n";
                    $return .= "\t\t\t<li class=\"head-list\">".$cat['categorie']."</li>\n";
                    $return .= $this->subcategorie($cat['categorie']);
                    $return .= "\t\t</ul>\n";
                    $return .= "\t</li>\n";
                    $i++;
                }
                $return .= "</ul>";

    }
    return $return;

}

最佳答案

试试这个:

function categorie($tab){
    global $mysql;
    $return = "";
    $categorie = $mysql->select(sprintf("SELECT * FROM categorii WHERE tab = '%d'", $tab));

    if($mysql->countRows() > 0){
        $i = 0;
            $return .= "<ul class=\"group\">\n";
                foreach ($categorie as $cat) {
                    if($i % 2 == 0 && !empty($i)){
                        $return .= "</ul><ul class=\"group\">";
                    }

                    $return .= "\t<li>\n";
                    $return .= "\t\t<ul>\n";
                    $return .= "\t\t\t<li class=\"head-list\">".$cat['categorie']."</li>\n";
                    $return .= $this->subcategorie($cat['categorie']);
                    $return .= "\t\t</ul>\n";
                    $return .= "\t</li>\n";
                    $i++;
                }
                $return .= "</ul>";

    }
    return $return;

}

关于php - 我该如何处理该除模误差?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23809580/

10-13 02:36