Re: [htmltmpl] Load & Display 1 Row From DBI - Best Practice?
Brought to you by:
samtregar
|
From: Dan H. <dan...@re...> - 2009-03-18 20:45:39
|
ad...@sp... said:
>>> I'm using HTML::Template from CGI::Application. My template is getting
>>> data via a SQL query where exactly one row
>>> retrieved, and it is displayed using <TMPL_LOOP>.
>>>
>>> What is the proper way set & display values returned from DBI when only
>>> one row is printed? I think the method described below may have a
>>> better alternative.
>>>
>>>
>>> Currently showing all records using a loop:
>>>
>>> 1. $template->param(
>>> 2. RESULTS => $self->dbh->selectall_arrayref('
>>> 3. SELECT age, day FROM table WHERE id = ?',
>>> 4. { Slice => {} },
>>> 5. $self->session->param('id') )
>>> 6. );
>>>
>>>
>>> Template:
>>>
>>> 1. <TMPL_LOOP NAME="RESULTS">
>>> 2. <TMPL_VAR NAME="age"><TMPL_VAR NAME="day">
>>> 3. </TMPL_LOOP>
>>>
>>Why not use selectrow_hashref()... then you get just the fields?
>>
>>Mathew
>
> So how would my above example look different if I used
> selectrow_hashref()? My trys aren't working.
>
>
Can you dump the output of the select using your original array_ref? I
believe what you have should work, but it could be something that we can't
see (e.g. Have you set case sensitivity in your template instantiation?
Oracle will return its column names in upper case)
|