And here is the response from the Dumper:my @names = @{ $sth->{NAME} }; my @ordered_values = (); while ( my $row = $sth->fetchrow_hashref ) { @ordered_values = @{$row}{@names}; } print Dumper(\@names); print Dumper(\@ordered_values); my $xs = XML::Simple->new( keyattr => {[cdr =>'npa' ]}, rootname => 'data +set' ); my $cgi = CGI->new; print $cgi->header('text/xml'); print XMLout( \@ordered_values );
So @names is correct, but I cannot get the column names into the element tags correctly. The ordered_values array also keeps getting overwritten, as the print statement only pulls up that last record of the query results, when there is like 500. So how do I get the values for @names as the element tags instead of anon?$VAR1 = [ 'NPA', 'GC_ID', 'I_TG_NAME', 'E_TG_NAME', 'DN', 'STATE' ]; $VAR1 = [ AAAABUcKyqQhEAABI34stA.4515613, '989', OQ-OZDN-D-UHMC-UHMC-0939, MQ-MTBO-T-CCDPN-FTQ-1737, 9895555555, MI ]; Content-Type: text/xml; charset=ISO-8859-1 <opt> <anon>AAAABUcKyqQhEAABI34stA.4515613</anon> <anon>989</anon> <anon>OQ-OZDN-D-UHMC-UHMC-0939</anon> <anon>MQ-MTBO-T-CCDPN-FTQ-1737</anon> <anon>9895555555</anon> <anon>MI</anon> </opt>
In reply to DBI hashref does not return data in order of query by hallikpapa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |