my $sth = ... print [all your html including the TABLE tag ] while (@row = ... { print [ code for each row] } print [ rest of html doc ]