in reply to Re^3: Best way to send records to the browser?
in thread Best way to send records to the browser?
Didn't mean to make it sounds like I'm an advocate for HT over TT2. I recognize the power TT2 provides, and I like what you can do with it. Just wish you could pass it arrays directly from Perl.
My MySQL query looks like this:
# issue query my $sth = $dbh -> prepare("SELECT uid, fname, lname FROM users") || &b +ail_out("Error: cannot prepare DB query"); $sth -> execute() || &bail_out("Error: cannot execute DB query");
The following loop yields an array with all relevant keys and values as individual elements. The results are printed to the terminal for testing:
while (@rray = $sth -> fetchrow_array) { $row{uid} = $rray[0]; $row{fname} = $rray[1]; $row{lname} = $rray[2]; push @rows, %row; } foreach (@rows) { print "$_\n"; }
This next variation is an attempt to build a hash instead of an array. It only builds one column (lname) from the table at this time. Keys are defined as records.
while (@rray = $sth -> fetchrow_array) { $record = "record_$i"; $hash{$record} = $rray[1]; $i += 1; } my ($key, $value); while (($key, $value) = each(%hash)) { print "key = $key, value = $value\n"; }
The two pieces of code above work. Finally, however, my attempt to build a HoH is failing. Here is what I have so far:
while (@rray = $sth -> fetchrow_array) { $record = "record_$i"; $hash1{fname} = $rray[1]; $hash2{$record} = %hash1; $i += 1; } while (($key, $value) = each(%hash2)) { print $hash2{$value} -> {fname}; }
There are obviously some problems here. Can you offer me some guidance?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Best way to send records to the browser?
by almut (Canon) on Jun 26, 2010 at 17:51 UTC | |
by Perobl (Beadle) on Jun 26, 2010 at 19:16 UTC | |
by almut (Canon) on Jun 26, 2010 at 19:45 UTC | |
by Perobl (Beadle) on Jun 26, 2010 at 21:52 UTC | |
|
Re^5: Best way to send records to the browser?
by Your Mother (Archbishop) on Jun 26, 2010 at 20:33 UTC | |
by Perobl (Beadle) on Jun 26, 2010 at 23:07 UTC |