How do I use a variable defined within a while loop, outside said loop?

Hi,

How do I use a variable I’ve defined in While loop outside of said loop? I’m using it to push a bunch of values into an array, and then I need to echo that array in another while loop. I don’t want to bore you with too many details, so I’ll put some example code to show what I mean.
[php]

<?php // Obviously most of the variables are gibberish, but I thought this might help. while ($query_row_2 = odbc_fetch_array($qr_2)) { while ($sum_row = odbc_fetch_array($qr_2)) { $r01 = array(); $r01_push = array_push($r01, $sum_row['SC01058']); $r01 = array_sum($r01); // The variable I need to use. } echo ' '.$query_row_2['SC01001'].' '.$query_row_2['SC01002'].$query_row_2['SC01003'].' '.$query_row_2['SC01058'].' '.$r01.' // Where I need to use said variable. '; } ?>

[/php]

$r01_push = array_push($r01, $sum_row['SC01058']); $r01 = array_sum($r01); // The variable I need to use.

looking at the inside while it doesn’t appear that $r01 contains any data, does it?

Well what I want is that as the odbc_fetch_array spits out values from rows from the SQL query, I need to find the sum of that row. The only way I can do this (or atleast the only way that I’ve come up with) is to put an array in a while loop that inserts every row into the array until the query stops. So I think $r01 contains data, but I may be going about this wrong /:

Sponsor our Newsletter | Privacy Policy | Terms of Service