<?php
require_once 'connect.php' ;
$sql = "SELECT Title,Date,Time,Location,image_url FROM events ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {$data = array();
while($row = $result->fetch_assoc()) {
$data['events'] = $row ;
}
}echo json_encode($data);
header('Content-Type: application/json');
?>
Вставьте записи в список, с небольшими предложениями
require_once 'connect.php' ;
$sql = "SELECT Title,Date,Time,Location,image_url FROM events ";
$result = $conn->query($sql);
// Move $data declaration up for zero result.
$data = array('events' => []);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Insert $rows in events array
$data['events'][] = $row ;
}
}
// Send headers first before sending any data
header('Content-Type: application/json');
echo json_encode($data);
Других решений пока нет …