Hi all,
I am struggling with some query result stuff.
I'm fairly new to perl and h::t
The query itself runs fine.
Below, between the ## 's.
I have tried to get some sort of if ( ) { else } around it (wondering if
that is a good solution anyway),
but don't manage to get it work.
This is the error I get:
[root@euro selling]# perl log_list.cgi
HTML::Template::param() : attempt to set parameter 'itemlist' with a scalar
- parameter is not a TMPL_VAR! at log_list.cgi line 83
[root@euro selling]#
Would anyone mind lending a hand?
Thanks,
Oscar
use DBI;
use HTML::Template;
use CGI;
use CGI qw/:standard :html3/;
use CGI qw/carpout fatalsToBrowser/;
require '../pg_tools.lib';
&get_my_input; #Split and decode the GET string, you call them with
$INPUT{whateverfield}
&sql_connect;
my $CGI = new CGI;
# grab the stuff from the database
my $sth = $dbh->prepare("
SELECT lognumber, logdate, logdescription
FROM log
WHERE logcontactnumber = '$INPUT{contactnumber}'
ORDER BY logdate DESC
");
$sth->execute();
my $rows;
#############################
my $rows = $sth->fetchall_arrayref(); # works when query is empty
#push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); # works when query
contains data
#############################
# prepare the template and substitute the values
my $template = HTML::Template->new(path => '../templates',
filename => 'log_list.tmpl',
associate => $CGI,
loop_context_vars => 1,
);
$template->param(ITEMLIST => $rows);
# print the goods
print $CGI->header;
print $template->output;
$sth->finish;
$dbh->disconnect;
Here the template:
<table width="100%">
<TMPL_LOOP NAME="ITEMLIST">
<tr>
<TMPL_IF NAME="__FIRST__">
<th class="header">LOGS</th></tr>
</TMPL_IF>
<TMPL_IF NAME="__ODD__">
<td class="tablerowodd"><a href=""
onClick="InfoWindow=window.open('log_show.cgi?lognumber=<TMPL_VAR
NAME="LOGNUMBER">','InfoWindow','toolbar=no, location=no, directories=no,
status=no, menubar=no, scrollbars=yes, resizable=yes, width=400,
height=400, left=350, top=200'); return false;"><TMPL_VAR
NAME="LOGDATE"> => <TMPL_VAR
NAME="LOGDESCRIPTION"></a></td>
<TMPL_ELSE>
<td class="tableroweven"><a href=""
onClick="InfoWindow=window.open('log_show.cgi?lognumber=<TMPL_VAR
NAME="LOGNUMBER">','InfoWindow','toolbar=no, location=no, directories=no,
status=no, menubar=no, scrollbars=yes, resizable=yes, width=400,
height=400, left=350, top=200'); return false;"><TMPL_VAR
NAME="LOGDATE"> => <TMPL_VAR
NAME="LOGDESCRIPTION"></a></td>
</TMPL_IF>
</tr>
</TMPL_LOOP>
</table>
__________________________________________________________________
Elbie.com
Oscar Buijten
Tel: +33.4.67.57.97.45
Fax: +33.4.67.57.97.46
GSM: +33.6.20.84.15.22
Email: [EMAIL PROTECTED]
Web: www.elbie.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]