id,name,description,parent_id #### sub getCategories() { my ($dbh)=@_; my $sth=$dbh->prepare("SELECT categories.id, categories.name, categories.description, categories.parent_id FROM categories"); $sth->execute(); my %cat_hash; while (my $cat_hashref = $sth->fetchrow_hashref()) { if ($cat_hashref->{parent_id}) { $cat_hash{$cat_hashref->{id}}{$cat_hashref->{parent_id}}{name}=$cat_hashref->{name}; $cat_hash{$cat_hashref->{id}}{$cat_hashref->{parent_id}}{description}=$cat_hashref->{description}; $cat_hash{$cat_hashref->{id}}{$cat_hashref->{parent_id}}{parent_id}=$cat_hashref->{parent_id}; } else { $cat_hash{$cat_hashref->{id}}{0}{name}=$cat_hashref->{name}; $cat_hash{$cat_hashref->{id}}{0}{description}=$cat_hashref->{description}; $cat_hash{$category_hashref->{id}}{0}{parent_id}='0'; } } $sth->finish(); return %cat_hash; }