Click here to Skip to main content
14,734,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have categories table .. (ID,ParentID,Title,Ordering)

----Unlimited level

i followed this wonderful tutorials

Infinite dynamic Multi-level nested category with PHP and MySQL – Roy Tutorials

all thing is good but,
1- i need to put the result in table . like this [image]
2- i need to put the result in select this [image]

thank you

What I have tried:

i followed this wonderful tutorials
Updated 21-Jun-18 20:34pm
Kornfeld Eliyahu Peter 26-Dec-16 13:26pm
No table, neither select box is for hierarchical data!!!
Golden Basim 26-Dec-16 13:33pm
what i do to show them in table ? ( like joomla categories page )
Kornfeld Eliyahu Peter 26-Dec-16 13:37pm
I do not know Joomla, but by instinct I would use an ordered/unordered list...
With table to get the same effect you have to inject a computed indentation according to the level...
Kornfeld Eliyahu Peter 26-Dec-16 13:40pm
By the way - how you have the data? In database?
Golden Basim 26-Dec-16 13:40pm
yes ..
i need to make like this

$connect = mysqli_connect("localhost", "root", "", "shopp");
$query = " SELECT * FROM maincategory ";
$result = mysqli_query($connect, $query);
//$output = array();
while($row = mysqli_fetch_array($result))
$sub_data["id"] = $row["id"];
$sub_data["category"] = $row["category"];
$sub_data["text"] = $row["category"];
$sub_data["p_id"] = $row["p_id"];
$data[] = $sub_data;
foreach($data as $key => &$value)
$output[$value["id"]] = &$value;
foreach($data as $key => &$value)
if($value["p_id"] && isset($output[$value["p_id"]]))
$output[$value["p_id"]]["nodes"][] = &$value;
foreach($data as $key => &$value)
if($value["p_id"] && isset($output[$value["p_id"]]))
echo json_encode($data);
/*echo '
echo '


url: "fetc.php",
dataType: "json",
success: function(data)
$('#treeview').treeview({data: data});

After many, many attempts

function buildCatTable($parent = 0 ,$level=0) {
       global $con;
       $getStmt = $con->prepare("SELECT * FROM productscatagories WHERE ParentID = ? ORDER BY ParentID,Ordering,ID ");
       $cats = $getStmt->fetchAll();

       foreach($cats as $cat) {
           echo "<tr>"."<td>". str_repeat("| - -  ".str_repeat('&nbsp;', $level), $level). $cat['Title'] . "</tr>"."</td>";
           buildCatTable($cat['ID'] ,$level +1);


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900