k_rajesh has asked for the wisdom of the Perl Monks concerning the following question:
The SELECT statement would be as follows:sub get_tmpl_loop_arrayref_bind #Given an SQL query this will return an arrayref compatible with TMPL_ +LOOP. Works where the query does not contain a , before the 'from' an +d where there is no subquery. { my ($dbh, $sql, @binds, $sessID) = @_; $dbh->{RaiseError}=0; $dbh->{PrintError}=0; $sql=~/select\s+(.*?)from\s+.*/ig; my $onlyfields = $1; my @fields = split /,/, $onlyfields; foreach my $field (@fields) { $field=$1 if ($field=~/.*?\s+as\s+\[(.*)\]/ig); #Fields taken with the + as identifier are parsed here. Eg. "select a/b as ratio" $field=~s/\s+//ig; } my $sth = $dbh->prepare($sql) || die "Could not prepare query $sql in +get_tmpl_loop_arrayref"; $sth->execute || die "Could not execute query $sql in get_tmpl_loop_ar +rayref"; my @loop_data = (); while (my $hash_op = $sth->fetchrow_hashref('NAME_lc')) { my %row_data; foreach my $field (@fields) { $row_data{$field}=$hash_op->{$field}? $hash_op->{$fiel +d}:'-' ; } $row_data{id}=$sessID if $sessID; push (@loop_data, \%row_data); } if ($dbh->errstr()) { return $dbh->errstr(); } else {return \@loop_data;} }
and the HTML:Template would be like so:"SELECT username, name, role, email, phone, mobile, creation_date from + user where creator='".$session->param('username')."'";
<TMPL_LOOP NAME=all_users> <!-- Data display --> <TR> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=username></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=name></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=role></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=email></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=phone></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=mobile></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=creation_date></TD>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling MS-Access date time
by Zed_Lopez (Chaplain) on Oct 08, 2005 at 07:44 UTC | |
|
Re: Handling MS-Access date time
by Errto (Vicar) on Oct 08, 2005 at 21:34 UTC |