I have a function called selectAll that returns results as objects.
$customers = $app['database']->selectAll('customers');
Below is the var_dump of the $customers variable:
array(4) {
[0]=> object(stdClass)#5 (7) { ["id"]=> string(2) "10" ["name"]=> string(10) "Thisted El" ["address"]=> string(13) "Otto Monsteds" ["city"]=> string(5) "Vej 8" ["phone"]=> string(9) "503982350" ["zip"]=> string(6) "481922" ["notes"]=> string(0) "" }
[1]=> object(stdClass)#6 (7) { ["id"]=> string(2) "11" ["name"]=> string(11) "Bibin Vinod" ["address"]=> string(8) "Kottayam" ["city"]=> string(5) "Kochi" ["phone"]=> string(10) "0294294022" ["zip"]=> string(6) "129042" ["notes"]=> string(0) "" }
}
I want to extract the 'name' property from these objects for an autofill form. I am using an autocomplete script found here.
In my PHP file, I have included the autofill function after the form. I encode this object using json_encode and then parse it using JSON.parse. By iterating over the array, I populate a JavaScript array with just the names and then pass it to the autocomplete function.
var js_data = '<?php echo json_encode($customers); ?>';
var js_obj = JSON.parse(js_data);
for (var i = 0; i < arrayLength; i++)
{
customername[i] = js_obj["name"];
}
autocomplete(document.getElementById("customers"), customername);
Despite following these steps, the autofill form does not work as expected. Any assistance on this matter would be greatly appreciated. Thank you.