首先,我使用以下内容从mysql
数据库获取所有数据:
$query = "SELECT * FROM locations";
$result = mysqli_query($link,$query);
while($row = mysqli_fetch_array($result)) {
$locations[] = $row;
}
我有map.js
文件,其中有标记数组:
markersData = {
'locations': [
{
type_point: 'TravelGuide',
location_latitude: 45.39579812501628,
location_longitude: 14.801673889160156,
map_image_url: 'img/thumb_map_must_8.jpg',
name_point: 'TravelGuide',
description_point: 'Palazzo Strozzi 9, Florence',
get_directions_start_address: '',
phone: '+3934245255',
},
{
type_point: 'TravelGuide',
location_latitude: 45.39579812501628,
location_longitude: 14.801673889160156,
map_image_url: 'img/thumb_map_must_8.jpg',
name_point: 'TravelGuide',
description_point: 'Palazzo Strozzi 9, Florence',
get_directions_start_address: '',
phone: '+3934245255',
}
我想要的是用php
数组填充此数组,但我需要使用foreach
,因此我可以根据需要加载任意数量的位置。所以它会是这样的:
type_point: 'TravelGuide',
location_latitude: $all['coordlat'],
location_longitude: $all['coordlng'],
foreach($locations as $all)
其中一个阵列就是这个
[ {"id":"98",
"ime1":"TravelGuide",
"ime2":"TravelGuide",
"adresa":"",
"email":"",
"mobitel":"(+385) --____",
"telefon":"(0__) -",
"koordinate":"45.39579812501628, 14.801673889160156",
"kategorija":"Apartman",
"opis1":"Proba za travelguide",
"opis2":"Travelguide test",
"aktivno":"1",
"photo":"generic.jpg"
}
]