http://qs321.pair.com?node_id=804250


in reply to fetchrow_hashref within a loop yields "fetch() without execute()"

$sth_spaces->execute(); ... foreach my $regid ( ... ){ ... foreach my $insid ( ... ){ ... while ( my $space = $sth_spaces->fetchrow_hashref() ){

In the first pass of the inner foreach in the first pass of the outer foreach, the while loop fetches all available data. There's none left for any other pass of the inner foreach loop, much less for other passes of the outer foreach.