Re: [htmltmpl] Load & Display 1 Row From DBI - Best Practice?
Brought to you by:
samtregar
From: <ad...@sp...> - 2009-03-18 18:46:47
|
>> 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. |