Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

DBI, HTML::Template and loops

by Anonymous Monk
on Apr 17, 2005 at 09:16 UTC ( #448608=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am new to perl, and I have been taking pieces and parts from other scripts I have found in an effort to try and get comfortable with perl. I am trying to query a database and display the information that I get on a webpage using HTML::Template.

Here is what I am using to get the data:

my $sth = $dbh->prepare( "SELECT alpha FROM main WHERE alpha LIKE '%$s +earch_ip %'" ); $sth->execute(); my ($complete_match) = $sth->fetchrow_array;
That gets my information out of the database, but how do I get that into HTML::Template? I have tried this:
$template->param(cm => $complete_match); print $CGI->header( ); print $CGI->title("returned data!"); print $template->output;
That gives me the follwoing error:

HTML::Template::param() : attempt to set parameter 'cm' with a scalar - parameter is not a TMPL_VAR! at /var/www/asd/www.pl line 60

If someone could point me in the right direction, it would be much appreciated.

Thank you very much.

Comment on DBI, HTML::Template and loops
Select or Download Code
Re: DBI, HTML::Template and loops
by borisz (Canon) on Apr 17, 2005 at 09:28 UTC
    Your template must include
    <tmpl_var cm> ...
    also take a look at placeholders for you SQL statements and at the die_on_bad_params option for HTML::Template
    Boris
Re: DBI, HTML::Template and loops
by bradcathey (Prior) on Apr 17, 2005 at 12:56 UTC

    $complete_match must be a ref to a AoH (array of hashes) for a <tmpl_loop>

    Consider:

    my $complete_match = $sth->fetchall_arrayref({}); $template->param(someloop=>$complete_match); HTML: <tmpl_loop someloop> <tmpl_var column1><tmpl_var column 2> etc... </tmpl_loop>

    Update: That error can also be caused by naming your form element the same name as your tmpl_loop name. They have to be different.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://448608]
Approved by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-05 09:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls