title: OOP PHP output data from class function
body: <p>I have a function within a class that queries the MySQL database for data, which will grab about 10 rows from the database.</p>
  
  <p>Example code:</p>
  
  <pre><code>&lt;?php
  
   class details {
  
   public function detailsRetrieve() { 
      try {
  
          $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
          $con-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  
          $sql = "SELECT * FROM table";
          $result = $con-&gt;query($sql);
  
          while($row = $result-&gt;fetch(PDO::FETCH_ASSOC)) {
          $1 = $row['row1'];
          $2 = $row['row2'];
          $3 = $row['row3'];
          $4 = $row['row4'];
  
          }
  
      $con = null;   
  
      }catch(PDOException $e) {
  
      echo $e-&gt;getMessage();
  
      }
   }   
       }
       ?&gt;
  </code></pre>
  
  <p>Now that works fine and gets the data from the database.
  I have included the class in a seperate page like so:</p>
  
  <pre><code>    &lt;?php
      include("class/details.php"); 
      $class = new details();
      $class-&gt;detailsRetrieve();
      ?&gt;
  </code></pre>
  
  <p>How can I actually output the variable (1,2,3,4) on this new page?</p>
  
  <p>I know that if I echo each of those variables inside of the function they will automaticly show on the new page just by using the above code, but I can I output each one seperately where I need on the page?</p>