in reply to Re: Creating a csv from two database tables
in thread Creating a csv from two database tables
An example script would be helpful - note my example listing is significantly reduced - the tables contain many thousands of rows in reality. I guess the way ive been going about it so far is:
while ($row = $sth->fetchrow_arrayref){ if (!defined($objects{$row->[0]})) ## not seen this object before, so +add it to the hash { $objects{$row->[0]} = $row->[1]; }else{ $objects{$row->[0]} = $objects{$row->[0]}.','.$row->[1]; ## se +en this object so append to csv } } while ($header_row=$header_sth->fetchrow_arrayref){ $headers .= "\"$header_row->[1]\"".','; } print $headers,"\n"; while (($k,$v)=each(%objects)){ print $v,"\n"; }
That is probably the worst way to go about it, and im not even sure it works all the time, or takes account for missing values. For example that will print out the headers, but the data items will not match if one value is missing
I hope this is clearer (probably not :))
Thanks
-----
Eschew obfuscation, espouse elucidation!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Creating a csv from two database tables
by linuxer (Curate) on Apr 06, 2009 at 16:43 UTC | |
|
Re^3: Creating a csv from two database tables
by linuxer (Curate) on Apr 06, 2009 at 15:23 UTC | |
by joec_ (Scribe) on Apr 06, 2009 at 15:30 UTC |