in reply to Re^6: Help with MySQL SELECT into multidimensional array
in thread Help with MySQL SELECT into multidimensional array
To generate your output, make an array to specify the column order: my @order = qw (fieldC fieldB fieldA); Then when processing each client, cycle through the order array, if value exists for that client, put it, if not then put "" or whatever. I am just thinking that a hash representation will work out better for accumulating the data, then make the 2D array for output after the data has been collected rather than keeping each row's columns straight during the data accumulation phase.use Data::Dumper; my %hash; my $client = "client1"; $hash{$client}{fieldA} = 12234; #from another query: $hash{$client}{fieldC} = 9876; print Dumper \%hash; __END__ $VAR1 = { 'client1' => { 'fieldA' => 12234, 'fieldC' => 9876 } };
Update: I mentioned before that there is more than one way to retrieve the data, one of those ways is as a hash. That might be of use to you...you have a bit of reading to do!
use Data::Dumper; my %hash; my $client = "client1"; $hash{$client}{fieldA} = 12234; #from another query: $hash{$client}{fieldC} = 9876; my @order = qw (fieldC fieldB fieldA); foreach my $client (keys %hash) { print "$client"; foreach my $field (@order) { if (exists $hash{$client}{$field}) { print "\t$hash{$client}{$field}"; } else { print "\tno_value"; } } print "\n"; } #prints: client1 9876 no_value 12234
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Help with MySQL SELECT into multidimensional array
by btongeorge (Initiate) on Dec 02, 2011 at 16:54 UTC | |
by Marshall (Canon) on Dec 02, 2011 at 17:05 UTC | |
by btongeorge (Initiate) on Dec 02, 2011 at 17:20 UTC | |
by Marshall (Canon) on Dec 02, 2011 at 18:57 UTC |