我遇到了問題,只能從mysqli一次打開一個結果集。 特別是我試圖通過選擇查詢循環並在執行操作後更新該查詢中的列。從更新查詢中使用的select查詢得到的mysqli結果
$db = new mysqli($DBServer, $DBUser, $DBPass , $DBName);
$sql = 'SELECT UPRN, POSTCODE FROM T_TEMP';
$stmt = $db->prepare($sql);
$stmt -> Execute();
<Create an array from the above select statement as i understand that mysqli can
only hold one result set at once (seems odd). I am unsure how to do this such that
i can then reference UPRN and POSTCODE later>
$stmt->Close();
$sql = 'update T_TEMP set LAT = ?, LONG = ? where UPRN = ?';
$stmt = $db ->prepare($sql);
<loop through that array built above grabbing UPRN and POSTCODE as you go through>
$postcode = urlencode(<Reference the postcode in the array>);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=false";
$xml = simplexml_load_file($request_url);
$lat = round(floatval($xml->result->geometry->location->lat),4);
$long = round(floatval($xml->result->geometry->location->lng),4);
$stmt -> bind_param('ddi',$lat,$long,$UPRN);
$stmt -> Execute();
<end loop>
我與得到所述第一查詢的結果到一個數組,然後引用該環內的陣列,所以我可以設置的值掙扎。 任何幫助非常感謝!
告訴我們您的陣列?這將有很大的幫助。 – IROEGBU
我沒有陣列,我知道我需要建立一個陣列,但我不確定如何去做。我將編輯代碼,使其更加明顯,我卡住了。 – Culture