$r = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($r)) $rows[] = $row; echo json_encode($rows);