Insérer une fonction javascript dans du php
J'ai besoin d'aide SVP
Le truc c'est que je dois mettre dans mon site, une carte qui contient des lieux de ma base de données. Du coup j'ai réussi à afficher une carte sauf que je n'arrive pas à insérer des marqueurs qui correspondent à ces lieux.
voilà mon code javascript
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <body>
<div id="mapdiv"></div>
<script>
map = new OpenLayers.Map("mapdiv");
map.addLayer(new OpenLayers.Layer.OSM());
var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var zoom=8;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
map.setCenter (lonLat, zoom);
</script>
</body> |
Puis mon php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php
$connexion = mysqli_connect('127.0.0.1', 'root', '' , 'projetlif4');
if(mysqli_connect_errno())
{
printf("Echec de la connexion : %s\n", mysqli_connect_error());
exit();
}
$position = 'SELECT latitude, longitude FROM lieux ;';
$resultat = mysqli_query($connexion, $position);
while ($row = mysqli_fetch_assoc($resultat))
{
echo '<script>
var new OpenLayers.LonLat( '.$row['latitude']. ',' .$row['longitude']. ')
.transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
markers.addMarker(new OpenLayers.Marker(lonLat));
</script>';
}
?> |
Il n'y aucun marqueurs correspondants à mes lieux qui s'affiche. Le seul c'est celui qui a les coordonnes (
Code:
-0.1279688 ,51.5077286
)
Je pense que le problème est au niveau du while où j'ai appelé ma fonction javascript...
HELP ME PLEASE :?