I researched this subject many times but I could not find the right answer to my question. Let me explain it.
I'm creating an app with the Google Maps API where I want to have multiple locations shown on the map, based on my database values. I'm having an object called Locations in my javascript, where I store the the variables 'name', 'lat' and 'lon' (latitude, longtitude).
var Locations =
[{
name: 'test',
lat: 52.351753,
lon: 5.002035
},
{
name: 'test2',
lat: 52.390839,
lon: 4.908722
}];
This part is where I store my locations. Although this is working, it is hardcoded. So, I want to get all my mysql database values out of the database into my javascript variable dynamically. I foreach'd through the database entry's with PHP:
foreach ($query as $post)
{
?> <h1><?php echo $post['naam'] ?></h1>
<p><?php echo $post['plaats'] ?></p>
<p><?php echo $post['categorie'] ?></p>
<?php
}
Now I tried to get all of those values and put them into my javascript variable, but without any succes.
var bedrijven = <?php echo json_encode($post); ?>;
When I console.log 'bedrijven' i'm only getting the last entry, but I want every row stored. Can someone help me with this? Would be really cool if it worked.
I hope I explained well enough.
Thanks!