Re: Array headaches - gone
| From: | Darren Beale | Date: | Fri, 04 Aug 2000 22:32:06 +0000 |
| Subject: | Re: Array headaches - gone | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10204@lists.php.net to get a copy of this message | ||
Bill, Phillip, *thankyou*
Using both your examples, I've ended up with this, exactly what I wanted @
9am this morning
function indent_cats($array,$parent,$prepend="  ",$level=0) {
for ($x=0;$x<$level;$x++) {
$prefix .= $prepend;
}
$top = ($parent == 0)?'<BR>':'';
while (list ($key, $value) = each ($array[$parent])) {
print "$top$prefix $value<BR>\n";
if($array[$key]){
$level++;
indent_cats($array,$key,$prepend,$level);
}
}
}
$indent_pixel = "<img src=\"../images/pixel.gif\" align=\"absmiddle\"
width=\"30\" height=\"1\">";
$sql = "select catID,parentID,category from categories order by category
asc";
$get_categories = do_sql($sql);
while($loop = mysql_fetch_array($get_categories)){
$cat_matrix[$loop["parentID"]][$loop["catID"]] =
eregi_replace("_","
",$loop["category"]);
}
echo display_array($cat_matrix,0,$indent_pixel);
Bealers