my $counter = 0; while (@ary = $sth->fetchrow_array ()) { if ($ary[$counter] == NULL){ print join("\t",@array[$counter]), " ","\n"; $counter++; } else { print join("\t",@array[$counter]), $ary[$counter],"\n"; } $counter++; }
The problem seems to be multi-fold. First, my MySQL query is returning 10 rows when I need just one row (I realize this is not a question for the Perl monks, but I promise the next one is).
The main issue is that the while iteration is only running 10 times (the number of rows that fetchrow_array is retrieving) and there are more than 10 possible data labels that are to be printed in the left column of the data output. Some of the data will not yet be in the database (and it is not at the end of the data query but rather in some of the middle fields), so I tried to skip the null data fields by incrementing count, but then the problem still remains that the while loop is not going to retrieve the last several data fields to output because its already iterated 10 times and there are still several more data fields in array beyond that. I need to know how to print all labels in my hardcoded @array and also retrieve all possible data fields from the MSQL query so that for each possible data field there is a label printed to the left, regardless of whether there is data to the right of it.
Thanks in advance for any help.In reply to formatting output from a mysql query in column format by thuperuser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |