putting subcategories of categories into arrays
| From: | Stephen Schneider | Date: | Fri, 21 Jul 2000 15:51:53 +0000 |
| Subject: | putting subcategories of categories into arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7588@lists.php.net to get a copy of this message | ||
I have a database that contains a field called categories. I have several
different categories listed. For each category there may be several
subcategories.
I am using the following to pull all of the categories out of the database:
while ($myrow = mysql_fetch_array($result)){ $category = $myrow[0];
$cat[] = $category; } ;
$catLimit = count($cat);
Now I need to get each subcategory for any category. I am using:
for($i=0; $i < $catLimit; $i++) {
$result = mysql_query("select distinct(subcategory) from links where
category = '$cat[$i]';",$db);
while ($myrow = mysql_fetch_array($result)){
$subcategory = $myrow[0];
$sub[$cat[$i]] = $subcategory;
}
}
here's where I'm stuck, and maybe it is easier than I'm making it. I want
to loop through and display a category and under it display all it's
subcategories. I'm getting parts of what I want but not just what I want.
Can someone help me out with a bit of code to show me what I need to do?
Thanks
Stephen Schneider - MCSE
Web Developer
HKM Direct Market
(216) 651 - 9500 (243)
sschneider@hkmdm.com