Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: using CGI, DBI and HTML::Template (a mini tutorial with example code)

by markjugg (Curate)
on Feb 12, 2002 at 15:34 UTC ( [id://144882]=note: print w/replies, xml ) Need Help??


in reply to using CGI, DBI and HTML::Template (a mini tutorial with example code)

selectall_hashref() only works in a limited number of versions of DBI (maybe 1.15 through 1.19). For the newest versions, 1.20 and greater I believe, you can get the same functionality that you are looking for like this:

selectall_arrayref($sql,{ Slice => {} });

selectall_hashref does something different in the newest versions and your old code will break.

Here's another way to process your DB output as well:

my $rows = $DBH->selectall_arrayref($sql,{ Slice=>{} }); for (@$rows) { # add key/value for Pi to every row. $_->{pi} = 3.14; }

For even lazier form re-filling, look into adding HTML::FillInForm into the mix. Then you don't even have to add the <tmpl> tags into your forms in many cases. I use this in conjuction with HTML::Template. There is as outdated tutorial on using these here. It's outdated because HTML::FormValidator has been superceded by Data::FormValidator.

-mark

Replies are listed 'Best First'.
Re: Re: using CGI, DBI and HTML::Template (a mini tutorial with example code)
by gav^ (Curate) on Feb 12, 2002 at 16:47 UTC

    Thanks for the tip, I just upgraded from 1.15 to 1.201 and found this broken. Now I'm worried as I have to make sure nobody upgrades DBI and causes all my scripts to break.

    gav^

      Good Tutorial, though l have to admit l did get caught out my the selectall_hashref and after searching this site, l found an easy solution to it:
      my $table_data = $dbh->prepare($companyquery); $table_data->execute; my $arrayref = $table_data->fetchall_arrayref({}); $template->param(ROWS => $arrayref);
      Hope this helps
        This one works much better. Thanks alot for sharing it with me. I really need it

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://144882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found