query($sql); $data = []; if ($result) { while ($row = $result->fetch_assoc()) { $data[] = $row; } } header('Content-Type: application/json'); echo json_encode($data); ?>