Skip to content

Instantly share code, notes, and snippets.

@navarr
Created May 25, 2010 15:09
Show Gist options
  • Select an option

  • Save navarr/413232 to your computer and use it in GitHub Desktop.

Select an option

Save navarr/413232 to your computer and use it in GitHub Desktop.
<?php
$q = $db->query("SELECT * FROM `gallery_categories` ORDER BY `parent` ASC,`order` ASC");
while($r = $db->fetch_assoc($q))
{
if($r["parent"])
{
if(!isset($cats[$r["parent"]]["children"])) { $cats[$r["parent"]]["children"] = array(); }
$i = count($cats[$r["parent"]]["children"]);
$cats[$r["parent"]]["children"][$i] = $r;
$cats[$r["id"]] = &$cats[$r["parent"]]["children"][$i];
} else {
$i = count($categories);
$categories[$i] = $r;
$cats[$r["id"]] = &$categories[$i];
$cats[$r["id"]]["children"] = array();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment