Re: putting subcategories of categories into arrays
| From: | Greg Donald | Date: | Fri, 21 Jul 2000 16:01:34 +0000 |
| Subject: | Re: putting subcategories of categories into arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7591@lists.php.net to get a copy of this message | ||
On Fri, 21 Jul 2000, Stephen Schneider wrote:
> 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
>
>
You might want to download a copy of phpLinks at
http://phplinks.destiney.com/ and have a look at my
source, I have a
really good category/subcategory system working.
Greg
--
------------------------------------------------------------------------
destiney - (des-ti-ny) - n. 1. deity of all things "html", 2. common
internet addict, 3. lover of late 80's heavy metal music, 4. Activist
for the terminally un-elite; see also - cool guy, des, mr. php...
It's 4:00am, your web site is still up, why are you?
http://destiney.com/
------------------------------------------------------------------------