我正在尝试使用JSON来建议来自mysql数据库的搜索项目,但是当我在输入框中输入任何内容时,数据库中的所有结果都会显示,并且根据输入文本它们不会被细化。
这是我的html / php UI页面:
<!-- Start of content --> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#searchText" ).autocomplete({ source: 'includes/functions/json_search.php', minLength:'2' }); }); </script> <div class="ui-widget"> <label for="searchText">Search the menu: </label> <input id="searchText" name="searchText"> </div>这是我的PHP:
<?php include_once ("../../config/init.php"); //get search term $searchTerm = $_GET['searchText']; //get matched data from menu table $query = $connection->query("SELECT * FROM menu WHERE name LIKE '%".$searchTerm."%' ORDER BY name ASC"); while ($row = $query->fetch_assoc()) { $data[] = $row['name']; } //return json data echo json_encode($data); ?>任何人都可以建议为什么它不会改进结果? 谢谢
I am trying to use JSON to suggest search items from the mysql database in php but when I type anything in the input box, all results from the database are showing and they are not being refined depending on the input text.
Here is my html/php UI page:
<!-- Start of content --> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#searchText" ).autocomplete({ source: 'includes/functions/json_search.php', minLength:'2' }); }); </script> <div class="ui-widget"> <label for="searchText">Search the menu: </label> <input id="searchText" name="searchText"> </div>Here is my php:
<?php include_once ("../../config/init.php"); //get search term $searchTerm = $_GET['searchText']; //get matched data from menu table $query = $connection->query("SELECT * FROM menu WHERE name LIKE '%".$searchTerm."%' ORDER BY name ASC"); while ($row = $query->fetch_assoc()) { $data[] = $row['name']; } //return json data echo json_encode($data); ?>can anyone suggest why it will not refine the results? thanks
最满意答案
//get search term $searchTerm = $_GET['searchText'];应该:
$searchTerm = $_GET['term'];每个jqueryui自动完成文档
//get search term $searchTerm = $_GET['searchText'];自动完成插件不会过滤结果,而是使用术语字段添加查询字符串,服务器端脚本应使用该字段来过滤结果。
should be:
$searchTerm = $_GET['term'];Per jqueryui autocomplete doc
The Autocomplete plugin does not filter the results, instead a query string is added with a term field, which the server-side script should use for filtering the results.
更多推荐
发布评论