query($sql); $tableData = []; if ($result->num_rows > 0) { // Loop through each row of the result set while ($row = $result->fetch_assoc()) { // Add each row to the $tableData array $tableData[] = $row; } } echo json_encode($tableData); $conn->close(); ?>