in reply to Re^7: [Solved]: Can we use print <<HTML; twice in same file?
in thread [Solved]: Can we use print <<HTML; twice in same file?
See DBI.pm#selectall_hashref. For a small data set it saves a lot of code, and it returns a hashref keyed by whichever column you choose.
my $sql = 'SELECT name, display, active FROM comm_desk_widget_status WHERE user = ?'; my $href = $dbh->selectall_hashref( $sql, 'display', undef, 'admin' ); print_html( $href ); sub print_html { my $h = shift; foreach my $label (sort keys %{ $h } ) { my $html = "<td><form><input type='checkbox' name='$h->{ $label }->{ name } +' value='1'"; $html .= $h->{ $label }->{ active } ? ' checked' : ''; $html .= ">$label</form></td>\n"; print $html; } }
Update: forgot the bind param; HTML typo
|
|---|