my $sth = $dbh->prepare ( q{ SELECT medewerkers.voornaam, nieuws.id, nieuws.titel, nieuws.bericht, nieuws.aanmaakdatum FROM medewerkers RIGHT JOIN nieuws ON medewerkers.id = nieuws.medewerker_id }); $sth->execute() or die "$dbh->errstr\n"; if ($sth->rows >= 1 ) { my %nieuws; while( my ($voornaam, $id, $titel, $bericht, $datum) = $sth->fetchrow_array) { map { s/\n/\
\n/g } $bericht; $nieuws{$id} = [ "$voornaam", "$titel", "$bericht", "$datum", ]; } my @loop; foreach my $nieuws_id (sort keys %nieuws) { my ($voornaam, $titel, $bericht, $datum) = @{ $nieuws{$nieuws_id}}; my %nieuwsbericht = ( voornaam => "$voornaam", titel => "$titel", bericht => "$bericht", datum => "$datum", ); unshift(@loop, \%nieuwsbericht); }