Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fetchrow_array loading an array in an array ?

Status
Not open for further replies.

letsGo123

Programmer
Jun 8, 2004
10
US
i'm trying to populate an array with a reference to array returned by:fetchrow_array so that I can use the values more than once during in script
Code:
$counter = 0;
foreach $addedProduct (@cartData)
{

 my $query = "Select column1, column2, column3, column4, column5, column6, column7 from tableName where  id ='$id_value'";

 $sth = $dbh->prepare($query);

 if (!$sth) { die "Illegal query: $query" };

 $sth ->execute;
 while (@row = $sth->fetchrow_array) {
  @rowResults[$counter] = @row;
 }
 $sth->finish; 
 
 $counter=$counter+1; 
}
if i then:
print "$rowResults[0]<p>";
print "$rowResults[1]<p>";
print "$rowResults[2]<p>";

the results that are printed are only the first column of each row. not sure why the other 6 columns are not being populated into the array.

any help would be helpful. thanks.
 
paul - thanks for the reply:

but:
$rowResults[$counter] = @row;

& then:
print "@rowResults<p>";
print "$rowResults[0]<p>";
print "$rowResults[1]<p>";
print "$rowResults[2]<p>";

returns:
7 7 7
7
7
7

which is the size of @row.
 
My mistake, lack of carbs ...

Code:
 while (@row = $sth->fetchrow_array) {
  foreach (@row)
  $rowResults[$counter].="$_\t" ;
 }


Does this get you out?
--Paul


 
paul -

it does, thanks. go get some pasta and a pint.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top