update global variables inside while loop
<p>Can someone please explain the most efficient method to return a value from within a while loop, for use before the while loop initiated.<br>
Tried the following- </p>

<pre><code>echo $var1;
while($row = mysql_fetch_array($query1)){
    $var1 = $row[0];
}
</code></pre>

<p>Returns unset variable.</p>

<p>I also tried:</p>

<pre><code>$var1= 1;
echo $var1;
while($row = mysql_fetch_array($query1)){
    global $var1;    
    $var1 = $row[0];
}
</code></pre>

<p>Just echos 1. </p>
