1

My page tell me:

Notice: Undefined index

for all my variables. I'm a beginner in PHP and I tried with isset but it didn't work. Can you tell me how I can fix this? Here is my code:

<?php
function encode_for_google_map($dbrow) {
       $result = array (
         'id' => $dbrow['id'],
         'picture' => $dbrow['picture'],
         'name' => $dbrow['name'],
         'category' => $dbrow['category'],
         'address' => $dbrow['address'],
         'about' => $dbrow['about'],
         'location' =>
         array (
           'latitude' => $dbrow['latitude'],
           'longitude' => $dbrow['longitude'],
         ),
       );
       var_export(json_encode($result));
}
$db = mysqli_connect("localhost", "root", "", "parisdb");
$reponse = $db->query('SELECT * FROM paristable');
while ($donnees = $reponse->fetch_assoc()){
     $data[]= $donnees;
     $encode_donnees = encode_for_google_map($data);
}
echo $encode_donnees;
?>
chris85
  • 23,846
  • 7
  • 34
  • 51
  • You're no stupid or bad, you've not probably called the function properly. From what I see, your functions expects to get kind of array or object. var_dump the $data variable before you use it to call the function and see what you have in your hand. – MyLibary Jul 03 '17 at 13:56
  • You are making `$data` a multi-dimensional array. Just send `$donnees` to `encode_for_google_map`. – chris85 Jul 03 '17 at 14:04
  • Ok, i've got my $data array(1) { [0]=> array(8) { ["ID"]=> string(1) "1" ["picture"]=> string(40) "charles-marville-photo-paris-900x500.jpg" ["name"]=> string(16) "Charles Marville" ["about"]=> string(29) "Ceci est un quartier parisien" ["adress"]=> string(22) "62 Avenue Félix Faure" ["category"]=> string(4) "blue" ["latitude"]=> string(10) "48.8405818" ["longitude"]=> string(17) "2.286173299999973" } } – Alexandre Roussel Jul 03 '17 at 14:04

0 Answers0