spaceout has asked for the wisdom of the Perl Monks concerning the following question:
---------------------------------------------------------
| category_id | parent_id | category_name |
---------------------------------------------------------
That's easy enough...where I'm having trouble is retrieving this data in a way that makes it easy to place into a drop down list on a web page like this:
Category 1
- Subcategory 1
- Subsubcategory1
- Subsubsubcategory1
- Subsubsubcategory2
- Subcategory 2
- Subsubcategory1
- Subsubcategory2
- Subsubcategory3
This is what I have so far (not the entire script...just the relevant parts):
my ($category_list) = getCategories(); ### Trying to figure out how to loop through $category_list for (my $search_total=0; $search_total<=$#$category_list; $search_tota +l++) { # Do something with these: # $category_list->[$search_total]->{category_id} # $category_list->[$search_total]->{parent_id} # $category_list->[$search_total]->{category_name} } ### Used to do a single select to grab all categories sub getCategories { my ($results_data) = []; my $row = 0; my $sql = qq~SELECT category_id, parent_id, category_name FROM +ss_catalog_categories~; my $sth = $dbh->prepare($sql); $sth->execute; while (my @results = $sth->fetchrow_array()) { $results_data->[$row]->{category_id} = $results[0]; $results_data->[$row]->{parent_id} = $results[1]; $results_data->[$row++]->{category_name} = $results[2]; } $sth->finish; return ($results_data); }
Any suggestions on doing this correctly would be wonderful. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested Categories (Aka: How to build a child pointer tree from a parent pointer representation)
by demerphq (Chancellor) on Jan 03, 2005 at 19:36 UTC | |
by spaceout (Initiate) on Jan 03, 2005 at 19:52 UTC | |
|
Re: Nested Categories
by mpeters (Chaplain) on Jan 03, 2005 at 18:17 UTC | |
|
Re: Nested Categories
by punkish (Priest) on Jan 03, 2005 at 17:56 UTC | |
|
Re: Nested Categories
by jZed (Prior) on Jan 03, 2005 at 19:13 UTC | |
|
Re: Nested Categories
by osunderdog (Deacon) on Jan 03, 2005 at 18:01 UTC | |
|
Re: Nested Categories
by holli (Abbot) on Jan 03, 2005 at 18:49 UTC | |
by spaceout (Initiate) on Jan 03, 2005 at 19:08 UTC |