Always group reply so others can help and be helped, and to avoid
getting accidentally ignored.

"Because it's up-side down.
Why is that?
It makes replies harder to read.
Why not?
Please don't top-post." - Sherm Pendley, Mac OS X list

Aaron Huber wrote:
> 
> On 6/3/05, Wiggins d'Anconia <[EMAIL PROTECTED]> wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>>I am trying to send the output of a mysql query to a two dimensional array.
>>>
>>>This is what I've tried using push.
>>>
>>>while (@results = $sth->fetchrow_array ())
>>>{
>>>    $x = $results[0];
>>>    $y = $results[1];
>>>    push (@data,[$x],[$y]);
>>>}
>>>
>>>However, I don't get back a two dimensional array, I get back a single
>>>array of @data.
>>>
>>>Thanks. -Aaron
>>>
>>
>>Not sure if this is an exercise in how to build an AoA or if you are
>>really just trying to accomplish the goal and move on. In the latter
>>case, you can have DBI do it for you using 'fetchall_arrayref',
>>
>>my $array_of_arrays = $sth->fetchall_arrayref;
>>
>>use Data::Dumper;
>>print Dumper($array_of_arrays);
>>
>>You should probably read the docs for the method, assuming you care
>>about data integrity and error handling,
>>
>>http://search.cpan.org/~timb/DBI-1.48/DBI.pm#fetchall_arrayref
>>
>>HTH,
>>
>>http://danconia.org
>>
> 
> 
> 
> Dear Wiggins,
>
> Thank you for taking the time to reply to my post.  Actually, what I
> am trying to do here is build an array that can be used with GD::Graph
> to show the graphical representation of a MySQL query.  This module
> only takes in an AoA like:
>
> @data = ([1,2,3,4],[10,20,30,40]); # @arr[$x vals], [$y vals]
>

Currently this is an array (specifically an array of array references,
which we call an array of arrays), but actually the subroutine call
below is taking an array reference.

> and outputs a graph using this:
>
> my $image = $plot->plot([EMAIL PROTECTED]);
>

The notation above, C<[EMAIL PROTECTED]>, means you are passing an array 
reference.
A '\' before a sigil causes a return of a reference to the structure.

perldoc perlreftut
perldoc perlref

> When I use this code with the above mentioned array hard coded in it
> works like a charm, but none of the suggestions on the message board
> gave me this type of array that I needed.  Is the above @data var an
> AoA or is it something else?
>

It is an array of arrays. If the other postings did not work then you
need to show us more of the code, specifically your select statement. We
are working blind at this point, we were assuming you were returning the
data in the correct way. Did you try the 'fetchall_arrayref' call?
Assuming your select is correct, and you really are getting one row of
data to plot at a time then it should be all you need. If it does not
work, then you probably need to manipulate your select differently, but
we can't tell that.

Use Data::Dumper to explore what structure you have. Try first printing
the above hard coded structure so you know what to look for. Then try
multiple things until you get it the same.

perldoc Data::Dumper

-- Sample --
use Data::Dumper;
my @aoa = ([1,2,3,4],[10,20,30,40]);

print Dumper([EMAIL PROTECTED]);

> Thanks,
> Aaron Huber
>

HTH, good luck,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to