首页 > 代码库 > PHP无限极分类 - 3 - 分类目录

PHP无限极分类 - 3 - 分类目录

结合zui---Tree组件,实现分类目录。

目录结构同上一篇:

效果:

技术分享

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>zui</title>
    <link rel="stylesheet" href="http://www.mamicode.com/dist/css/zui.min.css">
</head>
<body>
    <?php
        $conn = mysql_connect(‘localhost‘, ‘root‘, ‘root‘);

        if($conn) mysql_select_db("yii", $conn);
        else die(‘database is connect false.‘);

        function get_str($id = 0) {
            global $flag;
            global $str;

            $sql = "select * from category where pid= $id"; 
            $result = mysql_query($sql);

            if($result && mysql_affected_rows()){
                if(!$flag){
                    $flag = 1;
                    $str .= ‘<ul class="tree tree-lines" data-ride="tree">‘;
                } else {
                    $str .= ‘<ul>‘;
                }

                while ($row = mysql_fetch_array($result)) {
                    $str .= "<li><a href=http://www.mamicode.com/‘#‘>" . $row[‘id‘] . "--" . $row[‘catename‘] . "</a>";

                    get_str($row[‘id‘]);
                }

                $str .= ‘</li></ul>‘;
            }
            

            return $str;
        }

        echo get_str(0);
    ?>
    
    <!-- ZUI Javascript 依赖 jQuery -->
    <script src="http://www.mamicode.com/dist/lib/jquery/jquery.js"></script>
    <script src="http://www.mamicode.com/dist/js/zui.min.js"></script>
</body>
</html>

PHP无限极分类 - 3 - 分类目录