<?xml version="1.0" encoding="windows-1252"?>
<node id="63435" title="(dkubb) Re: (2) Outputing data from mySQL query into format for use with HTML::Template" created="2001-03-10 03:11:22" updated="2005-08-01 03:20:49">
<type id="11">
note</type>
<author id="51797">
dkubb</author>
<data>
<field name="doctext">
&lt;p&gt;A great way to do what you want is built right into DBI, 
there is no need for extra code to build the data structure:&lt;/p&gt;

&lt;code&gt;my %attr = (
  dbi_fetchall_arrayref_attr =&gt; {},
);

my $statement = q{
  SELECT *
    FROM table
   WHERE field LIKE ?
};

$template-&gt;param(
  rows =&gt; $dbh-&gt;selectall_arrayref($statement, \%attr, $value),
);&lt;/code&gt;

&lt;p&gt;This uses a little known, and &lt;b&gt;undocumented&lt;/b&gt; feature in [cpan://DBI], where &lt;code&gt;selectall_arrayref()&lt;/code&gt; can be coerced into returning a reference to an array of hash references.  This is done through the use of the &lt;code&gt;\%attr&lt;/code&gt; hash reference passed to &lt;code&gt;selectall_arrayref()&lt;/code&gt;.&lt;/p&gt;</field>
<field name="root_node">
63391</field>
<field name="parent_node">
63391</field>
</data>
</node>
