Hi so I am attempting to return all the "people" from my database and then create an object of the "person" data, then at the end of each while loop add the person to the array. Outside of the while loop i am then encoding said array.
Below attached is my current code:
class person {
public $firstName = "";
public $lastName = "";
}
$people = array();
$result = mysqli_query($con,"SELECT * FROM People");
while($row = mysqli_fetch_array($result)) {
$firstName=$row['firstName'];
$lastName=$row['lastName'];
$e = new Person();
$e->firstName = $firstName;
$e->lastName = $lastName;
array_push($people, $e);
}
json_encode($people);
Many thanks