$sth = $dbh->prepare ("SELECT * FROM catalog_pet, item $where ORDER BY catalog_pet.product_id $limit"); my @colors =(); while (my $ref = $sth->fetchrow_hashref()) { my %color = ( 'item_id' => $ref->{'item_id'}, 'color' => $ref->{'color'} ); push @{$colors{$ref->{'item_id'}}}, \%color; } $sth->execute (@placeholder); $page = get_product_table ($sth);