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

cat1
--cat1.1
--cat1.2
---cat1.2.2
---cat1.2.3
---cat1.2.4
----Unlimited level
--cat1.3
cat2
cat3

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 box.like this [image]

thank you

What I have tried:

i followed this wonderful tutorials
Posted
Updated 21-Jun-18 20:34pm
v3
Comments
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
http://joomtraining.com.au/assets/categoryManager.jpg

<?php
//fetc.php
$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"]]))
{
unset($data[$key]);
}
}
echo json_encode($data);
/*echo '
';
print_r($data);
echo '
';*/

?>

$(document).ready(function(){
$.ajax({
url: "fetc.php",
method:"POST",
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 ");
       $getStmt->execute(array($parent));
       $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