I would like to retrieve objects from the database in JSON using PHP and MySql. I would just like to know how to do this without having to create an array? Can it be done?
If so, can I get an example of how that can be done with this draft piece of code?
$sql = "SELECT Email , FirstName, LastName,Contact FROM tblUser where UserID=sessionID";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array ($result)) {
$arr = array(
$row["Email"],
$row["FirstName"],
$row["LastName"],
$row["Contact"]
);
array_push($json, $arr);
}
$jsonstring = json_encode($json);
echo $jsonstring;