title: Passing variable between functions - php
body: <p>Below is an edited version of my actual code:</p>
  
  <pre><code>&lt;?php
  
  include ('login_info.php');
  
  class modernCMS {
  
  var $host;
  var $username;
  var $password;
  var $db;
  var $url;
  
  
  function connect(){
      $con = mysql_connect($this-&gt;host, $this-&gt;username, $this-&gt;password);
      mysql_select_db($this-&gt;db, $con) or die(mysql_error());
  
  mysql_set_charset('utf8');
  
  }
  
  
  function get_coordinates(){
  
  $sql ="select lat, lng from postcodes LIMIT 1;";
      $res = mysql_query($sql) or die(mysql_error());
      while($row = mysql_fetch_assoc($res)){
          $lat = $row['lat'];
          $lng = $row['lng'];
  
      }
  }
  
  
   function get_name(){
  
   $sql ="select name from places WHERE lat=$lat AND lng=$lng LIMIT 1;";
      $res = mysql_query($sql) or die(mysql_error());
      while($row = mysql_fetch_assoc($res)){
          $name = $row['name'];
  
  echo $name;
  
  
       }
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Then within a separate document i have an include for the file above. I call the function get name using the following: </p>
  
  <pre><code>&lt;?=$obj-&gt;get_name()?&gt;
  </code></pre>
  
  <p>get_name actually contains a calculation for calculating the distance between two points however because its a lengthy calculation i have left it out of the example above. </p>
  
  <p>Its important that i can just use $obj->get_name() to get the output for $lat and $lng </p>