简体   繁体   English

使用php将地址从mysql DB读入数组以进行地理编码

[英]Reading address from mysql DB into an array using php for geocoding

<?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; ?>];
}

//I would want the above addresses to be populated in the array just as the one below so I can geocode them. //我希望上面的地址与下面的地址一样填充到数组中,以便对它们进行地址编码。 The problem is I try to achieve this using php to push them in the array to have them as the one below but I can't seem to get it working. 问题是我尝试使用php将其推送到数组中以将其作为下面的数组来实现,但我似乎无法使其正常工作。 I am using php and javascript to achieve this. 我正在使用php和javascript实现此目的。

// ======= An array of locations that we want to Geocode ======== // =======我们要地理编码的位置数组========

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"
      ];

Just to show you the power of PDO, which in many ways is better than mysqli 只是为了向您展示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?>;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM