This code works, and outputs an array as intended, but throws the following error message:
PHP Notice: Trying to get property of non-object…
Here is my code:
$mysqli = new mysqli("localhost","user","pass","database");
$sql = "SELECT keyterm
FROM keyterms";
$results = $mysqli->query($sql);
while($result = $results->fetch_object()->keyterm)
$keyterms[] = $result;
fetch_object()will return null when there are no more results in your result set, so the last iteration of the while loop will attempt to access thekeytermproperty on a null value.You should assign the result object to
$resultand then access the property in the loop body, e.g.: