//############################################################################################### query($sql); // 執行查詢 //將查詢結果,輸出成json物件變數 $str="callBackdata(JSON.stringify(["; $i=0; while($row = $result->fetch(PDO::FETCH_BOTH)) { $str .="{\"id\":\"".$row['書籍編號']."\","; $str .="\"name\":\"".$row['書籍名稱']."\","; $str .="\"price\":\"".$row['價格']."\"}"; $i +=1; if ($i != $result->rowCount())$str .=","; }//end of while $str .="]));"; echo $str; ////釋放記憶體//////////////////////////// $conn = NULL; ?>