使用v2 API打印与表信息顺序不同的标记


print markers with v2 API with different order than the table info

我有一个SQL查询,我用mysql_fetch_array传递结果到一个while循环,我正在打印一个表。我的想法是,在每一行中包含相同的信息,我正在地图上建立标记。当我在构建地图时,问题是地图总是以表的最后一行为中心(C标记)。而不是这样,我希望地图中心的标记A(表的第一行)。

  <?php
   while($info4 = mysql_fetch_array($result4))
   {    
   ?>   

      // A function to create the marker and set up the event window
      function createMarker(point, name, html, flag) 
      {
        //set the icon of the marker        
        var letteredIcon = new GIcon(baseIcon);
        letteredIcon.image = "markers/"+flag+".png";
         // Set up our GMarkerOptions object
        markerOptions = { icon:letteredIcon };
        var marker = new GMarker(point, markerOptions);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        // add a line to the side_bar html
        side_bar_html += '<td><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<'/a><'/td>';
         return marker;
      }

      // add the points   
      map.setCenter(new GLatLng(<?php print $info4['placeY'];?>,<?php print $info4['placeX'];?>), 14);    
      var point = new GLatLng(<?php print $info4['placeY'];?>,<?php print $info4['placeX'];?>);
      var marker = createMarker(point,"<?php print utf8_decode($info4['placeName']);?>","<?php print utf8_decode($info4['placeName'])."<br>".utf8_decode($info4['placeAddress'])."<br>".utf8_decode($info4['placeDistrict']);?>","<?=$flag;?>")
      map.addOverlay(marker);
    <?php  $flag=$flag+1;
    } ?> 

一个例子:表:

观光餐厅

B潮汐观光现象

C观光红房子

在这个例子中,地图以C标记为中心,而不是我想看到的A标记。

因此,不使用while循环,正确的代码如下:

    //make an array
    $rows = array();
while ($row=mysql_fetch_array($result4)){
//push the rows to the empty array
    array_push($rows, $row);
}
// reverse the order of the rows
$reversedarray=array_reverse($rows);
    //use the info of each row as the variable $info4 
foreach ($reversedarray as $info4) {
    //the code