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