Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 以树结构加载数据_Php_Mysql - Fatal编程技术网

Php 以树结构加载数据

Php 以树结构加载数据,php,mysql,Php,Mysql,Categories表在该表上有一个带有父id的Categories…而且每个Categories可能有很多子项…而且每个子项可能有很多内部子项。。。。我想通过动态地获取该父级的所有子级…。我无法获取超出某个级别的数据(意味着动态)…如何分别获取包含所有类别和其子类别的树结构…这可能吗 I want sort out the data from Categories table like tree structure as given below… ![树形结构][1] 从下面给出的“类别”表

Categories表在该表上有一个带有父id的Categories…而且每个Categories可能有很多子项…而且每个子项可能有很多内部子项。。。。我想通过动态地获取该父级的所有子级…。我无法获取超出某个级别的数据(意味着动态)…如何分别获取包含所有类别和其子类别的树结构…这可能吗

I want sort out the data from Categories table like tree structure as given below…
![树形结构][1]
从下面给出的“类别”表中。。。
!['CATEGORIES'表格图像][2]
[1]: http://i.stack.imgur.com/1oW5j.png
[2]: http://i.stack.imgur.com/dJ7ht.png
我的静态代码是
$list\u pcat\u q=mysql\u查询(“从父级\u id='0'所在的类别中选择*);
而($list\u pcat\u f=mysql\u fetch\u数组($list\u pcat\u q)){
$parent=摘录($list\u pcat\u f);
回声“;
$list\U scat\U q=mysql\U查询(“从父类id=$cat\U id的类别中选择*);
而($list\u scat\u f=mysql\u fetch\u数组($list\u scat\u q)){
摘录($list\u scat\f);
回声“;
$list\U sscat\U q=mysql\U查询(“从父类id=$cat\U id的类别中选择*);
而($list\u sscat\u f=mysql\u fetch\u数组($list\u sscat\u q)){
摘录($list\U sscat\U f);
回声“;
$list\u ssscat\u q=mysql\u query(“从父类\u id=$cat\u id和最终\u flag='1'的类别中选择*);
而($list\u ssscat\u f=mysql\u fetch\u数组($list\u ssscat\u q)){
摘录($list\U ssscat\U f);
回声“;
}
}
}
}

嘿,试试这个,告诉我它是否有效

![TREE STRUCTURE][1]


From the Table 'categories' as given below...

!['CATEGORIES' TABLE IMAGE][2]


  [1]: http://i.stack.imgur.com/1oW5j.png
  [2]: http://i.stack.imgur.com/dJ7ht.png



my static code is

$list_pcat_q = mysql_query("select * from categories where parent_id='0'");
            while($list_pcat_f = mysql_fetch_array($list_pcat_q)){
            $parent=extract($list_pcat_f);
            echo"<h3><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h3>";

                $list_scat_q = mysql_query("select * from categories where parent_id=$cat_id");
                while($list_scat_f = mysql_fetch_array($list_scat_q)){
                extract($list_scat_f);
                echo "<h4><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h4>";

                    $list_sscat_q = mysql_query("select * from categories where parent_id=$cat_id");
                    while($list_sscat_f = mysql_fetch_array($list_sscat_q)){
                    extract($list_sscat_f);

                        echo "<h5><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h5>";

                        $list_ssscat_q = mysql_query("select * from categories where parent_id=$cat_id and final_flag='1'");
                        while($list_ssscat_f = mysql_fetch_array($list_ssscat_q)){
                        extract($list_ssscat_f);

                        echo "<h6><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h6>";

                        }

                    }

                }

            }
函数childCount($parent\u id){
$query=mysql\u query(“从类别中选择*,其中parent\u id=“.$parent\u id”);
返回mysql\u num\u行($query);
}
函数getCategories($parent_id,$output='')
{
$output='
    '; $sql=“从类别中选择*,类别id!=”。$parent\u id; $query=mysql\u查询($sql); if(mysql_num_rows($query)>0) { while($category=mysql\u fetch\u array($query)) { 如果(儿童人数($category['cat_id'])>0) { $output.='
  • '.$category['cat_name']; $t=“and parent_id=”.$category['cat_id'”; $output.=getCategories($t); $output.='
  • '; } 其他的 $output.='
  • 。$category['cat_name'].
  • ; } } $output.='
'; 返回$output; } $t=“和父项id=0”; 回音分类($t);
嘿,试试这个,告诉我它是否有效

![TREE STRUCTURE][1]


From the Table 'categories' as given below...

!['CATEGORIES' TABLE IMAGE][2]


  [1]: http://i.stack.imgur.com/1oW5j.png
  [2]: http://i.stack.imgur.com/dJ7ht.png



my static code is

$list_pcat_q = mysql_query("select * from categories where parent_id='0'");
            while($list_pcat_f = mysql_fetch_array($list_pcat_q)){
            $parent=extract($list_pcat_f);
            echo"<h3><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h3>";

                $list_scat_q = mysql_query("select * from categories where parent_id=$cat_id");
                while($list_scat_f = mysql_fetch_array($list_scat_q)){
                extract($list_scat_f);
                echo "<h4><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h4>";

                    $list_sscat_q = mysql_query("select * from categories where parent_id=$cat_id");
                    while($list_sscat_f = mysql_fetch_array($list_sscat_q)){
                    extract($list_sscat_f);

                        echo "<h5><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h5>";

                        $list_ssscat_q = mysql_query("select * from categories where parent_id=$cat_id and final_flag='1'");
                        while($list_ssscat_f = mysql_fetch_array($list_ssscat_q)){
                        extract($list_ssscat_f);

                        echo "<h6><a href='categories_list.php?cate_id=$cat_id'>".$cat_name."</a></h6>";

                        }

                    }

                }

            }
函数childCount($parent\u id){
$query=mysql\u query(“从类别中选择*,其中parent\u id=“.$parent\u id”);
返回mysql\u num\u行($query);
}
函数getCategories($parent_id,$output='')
{
$output='
    '; $sql=“从类别中选择*,类别id!=”。$parent\u id; $query=mysql\u查询($sql); if(mysql_num_rows($query)>0) { while($category=mysql\u fetch\u array($query)) { 如果(儿童人数($category['cat_id'])>0) { $output.='
  • '.$category['cat_name']; $t=“and parent_id=”.$category['cat_id'”; $output.=getCategories($t); $output.='
  • '; } 其他的 $output.='
  • 。$category['cat_name'].
  • ; } } $output.='
'; 返回$output; } $t=“和父项id=0”; 回音分类($t);
我只是想说明这已经足够了……就像这张图片一样,这可能是点击家长sudhakar。这也是很好的很多…这没有问题…附加表的sql文件。hai有我的sql文件可用…请点击并下载此链接…非常好…输出非常适合我的概念…很好的工作sudhakar…非常感谢…只是我想表明这够了…就像这张图片,这可能是点击父sudhakar。这也是很好的很多…这没有问题…附加表的sql文件。hai有我的sql文件可用…请点击并下载此链接…非常好…输出非常适合我的概念…很好的工作sudhakar…非常感谢。。。。