when I run this:
if ($result->num_rows() > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
I get the following error:
Call to undefined method mysqli_result::num_rows()
I presume the error is from the num_rows()
method but can't quite figure out what is wrong. As far as I know, objects call methods by using $obj->foo()
in OOP but when I remove the parenthesis of num_row
:
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
this block of code runs as expected.