Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
G'Day. Seems I've lost my path to brain. Thought it was #!/usr/bin/brain -Tw

Dilemma ->
I'm querying a data base and I'm getting and expecting three rows of data. I'm trying to get the first row to be put in an array (@x). Then I want the second row in array y. And eventually I want the third row in array z.

$sth->execute() or die $sth->errstr; my $row = 0; while (my @result = $sth->fetchrow_array()) { last if $row++ >= 3; if ($row = 1){ @x = @result; } if ($row = 2){ @y = @result; } if ($row = 3){ @z = @result; } } print qq(@x<br><br>); print qq(@y<br><br>); print qq(@z<br><br>); $sth->finish();
If I put the print statement inside the while loop, each array prints all three rows. If I print outside the while loop, it prints only the last row for each array.

The complete return looks like this:
@result =
row 1 - data1
row 2 - data2
row 3 - data3

I need to get it to do this:
@x = row 1 - data1
@y = row 2 - data2
@z = row 3 - data3

Any suggestions and/or help would be most appreciated.

peppiv


In reply to pushing individual rows of return (DBI) into seperate arrays by peppiv

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-06-22 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (100 votes). Check out past polls.

    Notices?