Php infinite level column classification reading implementation code
- 2021-01-14 05:43:07
- OfStack
To implement the infinite column classification idea: get from the increment ID(also known as the parent ID) and then in the database to get the child ID(also known as uid child id) data as follows
id:1 uid:0 This is column 1
id:2 uid:1 This is column 2
id:3 uid:1 I am a subclass of column 1
Display results:
This is column 1
I'm a subclass of column 1
This is column 2
Here is the Php code
<?php
$query = $this->db->query("SELECT * FROM category");
$list = $query->result();
foreach($list as $v){
if($v->category_id == 0){// Get the parent column ( Is equal to the 0 All are father columns )
$categoryul = anchor("home/content/".$v->id,$v->category_name);
echo "<ul>".$categoryul."</ul>";
$listx = $this->Listx->list_id($v->id);// In according to the father id Displays the specified subcolumn
foreach($listx as $vid){
$category = anchor("home/content/".$vid->id,$vid ->category_name);
echo "<li>".$category."</li>";
}
}
}
?>