gpt4 book ai didi

javascript - 使用 php 将地址从 mysql DB 读取到数组中进行地理编码

转载 作者:行者123 更新时间:2023-12-03 05:15:19 29 4
gpt4 key购买 nike

<?php  
$query = mysqli_query($connection, "SELECT address1, address2, parish FROM `contestantsaddress`");
//Starts while loop so all addresses for the given information will be populated.
$addresses = array();
while($result = mysqli_fetch_array($query)) //instantiates array
{
$address1 = $result['address1'];
$address2 = $result['address2'];
$parish = $result['parish'];
//$country = $result['country'];

array_push($addresses1,$address1, $address2, $parish, $country);
$count++;
} //ends while


?>

for(var i=0; i<10; i++){
var addresses = [<?php echo $addresses; ?>];
}

//我希望将上面的地址填充到数组中,就像下面的地址一样,以便我可以对它们进行地理编码。问题是我尝试使用 php 来实现这一点,将它们插入数组中,使它们如下所示,但我似乎无法让它工作。我使用 php 和 javascript 来实现这一点。

//======= 我们想要地理编码的位置数组 ========

var addresses = [
'251 Pantigo Road Hampton Bays NY 11946',
'Amagensett Quiogue NY 11978',
'789 Main Street Hampton Bays NY 11946',
'30 Abrahams Path Hampton Bays NY 11946',
'3 Winnebogue Ln Westhampton NY 11977',
'44 White Oak Lane Montauk NY 11954',
'107 stoney hill road Bridgehampton NY 11932',
'250 Pantigo Rd Hampton Bays NY 11946',
'250 Pantigo Rd Hampton Bays NY 11946',
'44 Woodruff Lane Wainscott NY 11975',
'Address East Hampton NY 11937',
'Address Amagansett NY 11930',
'Address Remsenburg NY 11960 ',
'Address Westhampton NY 11977',
'prop address Westhampton Dunes NY 11978',
'prop address East Hampton NY 11937',
'Address East Hampton NY 11937',
'Address Southampton NY 11968',
'Address Bridgehampton NY 11932',
'Address Sagaponack NY 11962',
"A totally bogus address"
];

最佳答案

只是为了向您展示 PDO 的强大功能,它在很多方面都比 mysqli 更好

<?php  
$sql = "SELECT CONCAT_WS(' ',address1, address2, parish) FROM contestantsaddress";
$addresses= json_encode($pdo->query($sql)->fetchAll(PDO::FETCH_COLUMN));
?>
var addresses = <?=$addresses?>;

关于javascript - 使用 php 将地址从 mysql DB 读取到数组中进行地理编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41628814/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com