I have tried few things bet they don't seem to work, my code works fine if I populate the array myself without database therefore the problem is with retrieving data from database.
var countries = <?php
require('connection.php');
$query = 'SELECT product_name FROM products';
$result = mysqli_query($conn, $query);
while($products = mysqli_fetch_array($result, MYSQLI_NUM)){
echo json_encode($products);
//OR
//$products = mysqli_fetch_all($result, MYSQLI_NUM);
//echo json_encode($products);
}
?>;
This is the code I have tried but it is not working I am sending countries to a function
autocomplete(document.getElementById("myInput"), countries);
In this function I am parsing through the array in such a way
for (i = 0; i < arr.length; i++) {
/*check if the item starts with the same letters as the text field value:*/
/*here arr is the array 'countries' send to the function autocomplete*/
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {//code snippet
}}