Page 1 of 1

variable scope question within a for loop

Posted: Mon May 24, 2004 3:20 pm
by hillxy
hi,

how can I access a array whose value was assigned inside a for loop loop

code like
.....
$SQL = "select a_number from table";
$rs = mysql_query($SQL);
$nRows = mysql_num_rows($rs);
for ($i = 0; $i < $nRows; $i++)
{
$k = mysql_fetch_row($rs);
$dc_t0 = $k[0];
echo $dc_t0, " <br>";
}
echo $nRows, $dc_t0[1], "<br>";
.....

inner loop echo works fine, but outter echo command can not see the array.

Any idea?
thanks,
hillxy

Posted: Mon May 24, 2004 3:26 pm
by markl999
You should be using [$i] not in the loop.

Oh, What a stupid mistake I made!!

Posted: Mon May 24, 2004 3:30 pm
by hillxy
Thanks,
hillxy