I had to put this off to the side for a bit, and just got back into it. Here is what I am trying to get work:
my @names = @{ $sth->{NAME_uc} }; my @ordered_values = (); while ( my $row = $sth->fetchrow_hashref ) { @ordered_values = @{$row}{@names}; } print Dumper(\@names); print Dumper(\@ordered_values); my $cgi = CGI->new; print $cgi->header('text/xml'); my $testxml = XMLout( \@ordered_values, NoAttr => 1, RootName => 'dataset', ); print $testxml;
And here is the response from the Dumper:
$VAR1 = [ 'NPA', 'GC_ID', 'I_TG_NAME', 'E_TG_NAME', 'DN', 'STATE' ]; $VAR1 = [ undef, 'AAAABUcKyqQhEAABI34stA.4515613', undef, undef, undef, undef ]; Content-Type: text/xml; charset=ISO-8859-1 <dataset> <anon></anon> <anon>AAAABUcKyqQhEAABI34stA.4515613</anon> <anon></anon> <anon></anon> <anon></anon> <anon></anon> </dataset>
So @names is correct, but in the @ordered_values, I am getting a bunch of blank fields (checked if it was a query problem, it's not), and that gibberish line is actually data(the GC_ID field). Can you see what's wrong with the push I am doing? The XML::Simple function seems to want a hash of the data so it can put the key in the element tag, and the hash value inside the tags? <edit> Empty data was cause of the NAME_uc. Changed to NAME and it plugged in data, but everything still is ANON. Update This while loop also seems to overwrite the data in the @ordered_values array as when I print using XMLout (XML::Simple), there is only one XML entry.

In reply to Re^2: DBI hashref does not return data in order of query by hallikpapa
in thread DBI hashref does not return data in order of query by hallikpapa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.