douhao2026 2017-01-13 06:42
浏览 38
已采纳

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

<?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. I am using php and javascript to achieve this.

// ======= 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"
      ];
  • 写回答

1条回答 默认 最新

  • duanhuanzhi6431 2017-01-13 07:53
    关注

    Just to show you the power of PDO, which in many ways is better than mysqli

    <?php  
    $sql = "SELECT CONCAT_WS(' ',address1, address2, parish) FROM contestantsaddress";
    $addresses= json_encode($pdo->query($sql)->fetchAll(PDO::FETCH_COLUMN));
    ?>
    var addresses = <?=$addresses?>;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题