---------------------------------------------------------
| 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.
In reply to Nested Categories by spaceout
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |