NZ_Kiwis;11032707 wrote:Any ideas? i'm still looking for an answer
try something like this
$db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE );
$sql = "SELECT category_id, name, parent FROM category";
$res = $db->query($sql);
$cats = array();
while (list($id, $name, $parent) = $res->fetch_row()) {
$cats[$parent][] = array($id, $name);
}
$parentCat = 1; // set start category
listCats($parentCat, $cats);
//
// recursive function to list child categories
//
function listCats($id, &$cats, $level=0)
{
if (isset($cats[$id]))
foreach ($cats[$id] as $child) {
$indent = str_repeat('----', $level);
echo $indent . $child[1] . '<br>';
listCats($child[0], $cats, $level+1);
}
}