while($obj = mysql_fetch_object($query)) { array_push($ar, array ( "id" => $obj->id, "namel" => $obj->name )); } echo json_encode($ar);