Matthew, I don't understand what's wrong with Jason's example. If DBI yields
a result in the format HTML::Template understands, what's wrong with taking
advantage of that? How would you change his example to make it more indirect
and abstract?

I love HTML::Template. Especially in combination with CGI::Application. But,
sometimes a database structure naturally lends itself to a form structure.
Doesn't it? Why is it wrong to pump the SQL output directly to
HTML::Template?

Mark

----- Original Message ----- 
From: "Mathew Robertson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 03, 2004 8:26 PM
Subject: Re: [htmltmpl] Select/option How to set "selected"?


> What's really neat if you do it like that is you can use DBI's
> fetchall_arrayref method and be really snazzy:
>
> my $template = HTML::Template->new( 'filename' => 'file.TMPL' );
> my $sth = $dbh->prepare( <<_SQL_ );
> SELECT val,
>         text,
>         (if then else to return 'selected' or '') AS selected
> FROM table
> WHERE whatever...
> _SQL_
> $sth->execute();
> $template->param( 'OCCUPATION_LOOP' => $sth->fetchall_arrayref( {} ) );
> ## Note that the fetchall_arrayref doesn't save you computing time --
> ## it's only a shortcut and does the same thing as your loop to go
> ## through the results
> ---
>
> What's neat about this, too is that it simplifies the template code, as
> Puneet laid out.

Except that you have now tied your SQL statement directly to HTML syntax; in
which case... what is the point of using H::T -> you could generate HTML
output faster if you created an SQL statement which generated HTML directly.

The purpose of H::T is to decopule the data from the presentation.
Mathew


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id66&op=ick
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE. 
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to