title: calling a php class function inside of a while loop
body: <p>I want to retrieve the amount of employees all the companies have, but it doesn't call the function.</p>
  
  <p><strong>This is my Class:</strong></p>
  
  <pre><code>class Rimaxx {
  
  public $host = "";
  public $username = "";
  public $password = "";
  public $database = "";
  
  public function GetCompanies()
  {
  $conn = new mysqli ($this-&gt;host, $this-&gt;username, $this-&gt;password, $this-&gt;database);
  
  $sql = "SELECT * FROM freelancers";
  $result = $conn-&gt;query($sql);
  
  return $result;
  
  $conn-&gt;close();
  
  }
  
  public function CountEmployees($id)
  {
  $conn = new mysqli ($this-&gt;host, $this-&gt;username, $this-&gt;password, $this-&gt;database);
  
  $sql = "SELECT * FROM Werknemers WHERE Idbedrijf = '$id'";
  $result = $conn-&gt;query($sql);
  
  return $result-&gt;num_rows;
  
  $conn-&gt;close();
  }
  </code></pre>
  
  <p><strong>And here is where I define things:</strong></p>
  
  <pre><code>include('rimaxx.php');
  
  $rimaxx = new Rimaxx();
  
  $rimaxx-&gt;host = "23.12.12.32";
  $rimaxx-&gt;username = "xxx";
  $rimaxx-&gt;password = "xxxxxx";
  $rimaxx-&gt;database = "rimaxx";
  
  $companies = $rimaxx-&gt;GetCompanies();
  </code></pre>
  
  <p><strong>And here is my while loop:</strong></p>
  
  <pre><code> &lt;?php while($row = $companies-&gt;fetch_assoc()) { ?&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;?php echo $row["Bedrijf"]; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["Plaats"]; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["Postcode"]; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $row["Provincie"]; ?&gt;&lt;/td&gt;
                &lt;td&gt;&lt;?php echo $rimaxx-&gt;CountEmployees($row["Idbedijf"]); ?&gt;&lt;/td&gt;
              &lt;/tr&gt;
   &lt;?php }; ?&gt;
  </code></pre>
  
  <p>Please, can some body help my?</p>