Regarding JavaScript arrangement, I would like to repeat several contents in db.

Asked 2 years ago, Updated 2 years ago, 30 views

    $i = 0;
    while($row=mysql_fetch_array($result)){
        echo "locations[" .$i++ ."] = [" .$row['Latitude'] ."," .$row['Longitude'] ."];";
    }
    ?>
    for(i=0; i< locations.length; i++){
        var marker = new naver.maps.Marker({ 
            position: new naver.maps.LatLng(locations[i][0],locations[i][1]), map: map
        });
    }

The sauce looks like a stomach.

At that part

locations[i][0], locations[i][1] This is how the code goes...

If it's 100, I have to write down all 100. locations[i][i] I can't do it like this. Too simple a thought

I guess so I want to write it in one line so that I can call up several. Help me

jquery java

2022-09-22 08:20

1 Answers

What does it mean to write in one line...?

However, I think it would be good to write the data generation part in JSON as follows.

locations = [ [36.123,123.00], [31.04,126.01], .... ];

To do the above, change the code of the php part as follows.

// omit the front part
echo "locations=[";
$i=0;
while($row=mysql_fetch_array($result)){
  If($i++>0) echo ""; // from the second entry, prepend , .
  echo "[" . $row['Latitude'] . "," . $row['Longitude'] . "]";
}
echo "];";
?>


2022-09-22 08:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.