title: Using a variable outside of the while loop (scope)
body: <p>Small problem regarding scope in PHP, I can't seem to call the variable $report outside of the while loop. I have tried various things, including <code>return</code>. This doesn't work, the only two functions that work here are if I <code>echo</code> the variable <code>$report</code> inside the loop, or if I <code>print</code> it. Which I do not want to do, although it solves the problem, but I don't want random gibberish on the user's screen.</p>
  
  <p>I have been looking around for the last 15 or so minutes, and I haven't seen any problems quite like this one on here.</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code>&lt;?
  require "functions2.php";
  require "members.php";
  $query = "SELECT MAX(DOCid) as prevDOCid from reports";
  $result = mysql_query($query);
  
  while ($row = mysql_fetch_array($result)) {
      $prevDOCid = $row[prevDOCid];
  
  $thisDOCid = $prevDOCid+1;
  $report = "a"."b".$thisDOCid;
  
  
  }
  echo $report;
  ?&gt;
  </code></pre>