我没有从我的mysql数据库使用php的搜索结果。我尝试过使用mysqli和here的PDO风格。jQuery ui自动完成没有搜索结果
HTML
<div id="tags_wrapper">
<p>Tags</p>
<input type="text" class="txtTag" placeholder="Start entering tag.."> </input>
</div>
的jQuery:位于PHP页面在根/博客/ panel.php, '源' 位于根/博客/ _class/tag_filler.php。
<script type="text/javascript">
$(document).ready(function(){
$('.txtTag').autocomplete(
{
source:'/_class/tag_filler.php',
minLength: 2
});
});
</script>
PHP源[mysqli的]:Brisktilities.php创建的mysqli的一个实例,我下面使用。
include_once 'BriskUtilities.php';
$util = new BriskUtilities();
$mysqli = $util->getMysqli();
if(isset($_GET['term'])) {
$search = $_GET['term'];
if($queryTags = $mysqli->query("SELECT * FROM Tag_T WHERE tValue LIKE %".$search."% ORDER BY tValue ASC")) {
while($row = mysqli_fetch_array($queryTags)) {
$results[] = array('id' => $row['tID'], 'label' => $row['tValue']);
}
echo json_encode($results);
}
$mysqli->close();
}
PHP源[PDO]:仍然与PDO没有搜索结果。我的数据库是轻快,我的表是tag_t,我的连接工作正常。有什么建议么?
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass) or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if ($conn)
{
$ac_term = "%".$_GET['term']."%";
$query = "SELECT * FROM tag_t where tValue like :term";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['id'] = $row['id'];
$row_array['value'] = $row['tValue'];
array_push($return_arr,$row_array);
}
}
$conn = null;
echo json_encode($return_arr);
更新 GET“术语”未找到(改变源时,博客/ _class/tag_filler.php错误消失,但仍然没有返回搜索结果。我使用的是同一个页面上的数据库和它取得另一个表的罚款结果):
Failed to load resource: the server responded with a status of 404 (Not Found) [http] site.local/_class/tag_filler.php?term=an
Failed to load resource: the server responded with a status of 404 (Not Found) site.local/_class/tag_filler.php?term=and
GET site.local/_class/tag_filler.php?term=my 404 (Not Found) jquery-1.9.1.js:8526
我最近正在与jQuery和自动完成的搜索引擎。它使用MySQLi。我去了一个很好的教程的地方是http://youhack.me/2010/04/28/creating-a-fancy-search-feature-with-php-mysql-and-jquery/下载工作开箱即用,我简单地用我的代码替换了dabase,并对代码做了一些小改动。但它工作的很好,而且它是自动完成的。 –
感谢@ BenP.Dorsi-Todaro,我会看看它,看看它是否适用于我 – user2690805
值得一提的是,你从mysql注入修复引擎。 –