【发布时间】:2018-09-16 23:52:56
【问题描述】:
我尝试了一些东西,但它们似乎不起作用,如果我自己在没有数据库的情况下填充数组,我的代码可以正常工作,因此问题在于从数据库中检索数据。
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);
}
?>;
这是我尝试过的代码,但它不起作用 我正在向国家/地区发送功能
autocomplete(document.getElementById("myInput"), countries);
在这个函数中,我以这种方式解析数组
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
}}
【问题讨论】:
标签: javascript php arrays database