function cache_award_cats($award_cat_id = -1, $depth = 0, $display_award_cat_id = 0) { // returns an array of award cats with correct parenting and depth information // see makeforumchooser for an example of usage global $db, $award_cat_cache, $count; static $fcache, $i; if (!is_array($fcache)) { // check to see if we have already got the results from the database $fcache = array(); $award_cats = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "award_cat\n\t\t" . iif($display_award_cat_id, "WHERE award_cat_id = {$display_award_cat_id}", '') . "\n\t\t\tORDER BY award_cat_displayorder\n\t\t"); while ($award_cat = $db->fetch_array($award_cats)) { if ($display_award_cat_id) { $award_cat[award_cat_parentid] = -1; } $fcache["{$award_cat['award_cat_parentid']}"]["{$award_cat['award_cat_displayorder']}"]["{$award_cat['award_cat_id']}"] = $award_cat; } } // database has already been queried if (is_array($fcache["{$award_cat_id}"])) { foreach ($fcache["{$award_cat_id}"] as $holder) { foreach ($holder as $award_cat) { $award_cat_cache["{$award_cat['award_cat_id']}"] = $award_cat; $award_cat_cache["{$award_cat['award_cat_id']}"]['depth'] = $depth; unset($fcache["{$award_cat_id}"]); cache_award_cats($award_cat['award_cat_id'], $depth + 1, $display_award_cat_id); } // end foreach ($val1 AS $key2 => $forum) } // end foreach ($fcache["$forumid"] AS $key1 => $val1) } // end if (found $fcache["$forumid"]) }
function cache_award_cats($award_cat_id = -1, $depth = 0) { // returns an array of award cats with correct parenting and depth information global $db, $award_cat_cache, $count; static $awcache, $i; if (!is_array($awcache)) { // check to see if we have already got the results from the database $awcache = array(); $award_cats = $db->query_read("\n\t\t\tSELECT aw_c.*, COUNT(aw.award_id) AS items\n\t\t\tFROM " . TABLE_PREFIX . "award_cat AS aw_c\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "award AS aw USING(award_cat_id)\n\t\t\tGROUP BY award_cat_id\n\t\t\tORDER BY award_cat_displayorder\n\t\t"); while ($award_cat = $db->fetch_array($award_cats)) { $awcache["{$award_cat['award_cat_parentid']}"]["{$award_cat['award_cat_displayorder']}"]["{$award_cat['award_cat_id']}"] = $award_cat; } $db->free_result($award_cats); } // database has already been queried if (is_array($awcache["{$award_cat_id}"])) { foreach ($awcache["{$award_cat_id}"] as $holder) { foreach ($holder as $award_cat) { $award_cat_cache["{$award_cat['award_cat_id']}"] = $award_cat; $award_cat_cache["{$award_cat['award_cat_id']}"]['depth'] = $depth; unset($awcache["{$award_cat_id}"]); cache_award_cats($award_cat['award_cat_id'], $depth + 1); } // end foreach ($val1 AS $key2 => $award_cat) } // end foreach ($awcache["$award_cat_id"] AS $key1 => $val1) } // end if (found $awcache["$award_cat_id"]) }