query($sql); $json = []; while($row = $result->fetch_assoc()){ $json[$row['id']] = $row['name']; } echo json_encode($json); ?>