您好我正在使用PostCode Anywhere API订阅根据邮政编码获取地址,步骤1是根据邮政编码获取一系列地址,然后步骤2是保存该ID和完整地址详细信息在单独的表中。目前,我使用以下代码进行此操作:
global $strTableName;
$postcode= $params["value1"];
//Set Post Code Variables
$Key = $_SESSION["PAFKey"];
$SearchTerm = $postcode;
//Build URL Request
$url = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/xmla.ws?";
$url .= "&Key=" . urlencode($Key);
$url .= "&SearchTerm=" . urlencode($SearchTerm);
//Make the request to Postcode Anywhere and parse the XML returned
$file = simplexml_load_file($url);
//Check for an error, if there is one then throw an exception
if ($file->Columns->Column->attributes()->Name == "Error")
{
throw new Exception("[ID] " . $file->Rows->Row->attributes()->Error . " [DESCRIPTION] " . $file->Rows->Row->attributes()->Description . " [CAUSE] " . $file->Rows->Row->attributes()->Cause . " [RESOLUTION] " . $file->Rows->Row->attributes()->Resolution);
}
//Copy the data
if ( !empty($file->Rows) )
{
foreach ($file->Rows->Row as $item)
{
$Data[] = array('Id'=>$item->attributes()->Id,'StreetAddress'=>$item->attributes()->StreetAddress,'Place'=>$item->attributes()->Place);
$newStreetAddress = str_replace("'", "", $item["StreetAddress"]);
$newPlace = str_replace("'", "", $item["Place"]);
$sql = "insert into Global_temp_address (id, StreetAddress, Place, PostCode, AddedBy) values ('".$item["Id"]."', '$newStreetAddress', '$newPlace','$SearchTerm', '".$_SESSION["user"]."')"; CustomQuery($sql);
}}
这确实有效,但我只能通过创建临时表,然后使用两部分表单(第二部分用于在下拉列表中选择地址,选择此部分后,然后擦除临时表)来实现)。
这不是最好的过程,我想知道如何获取返回的数据并在弹出的下拉框或类似的东西中显示它?欢迎任何其他建议