【发布时间】:2016-01-05 07:13:30
【问题描述】:
autoNameSearch.php
<?php
$conn = mysql_connect("localhost","root","1234");
if(!$conn)
{
die('Could not connect : ' . mysql_error());
}
mysql_select_db("ProductDetails",$conn) or die("Could not select database");
// $searchTag = array();
$sql = mysql_query("select shortSearch from proddetail");
while($row = mysql_fetch_assoc($sql)) {
$search[]= '"'.$row['shortSearch'].'"';
}
productSearch.php
<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>
<!--<link rel="stylesheet" href="/resources/demos/style.css">-->
<script type="text/javascript" > var searchTags = new Array( <?php implode(',', $search)?>); for(var i=0; i<searchTags.length;i++){
searchTags.toString();
document.write("contains: " +searchTags[i]+ "<br>"); } document.write = searchTags;
$(function(){
searchTags
$("#key").autocomplete({
source: searchTags
}); }); </script>
<body>
<form method="post" action="displayProducts.php?go" id="searcform" target="display">
<div class="menubar" id="leftNavMenuBar">
<a href="#" class="hashAdded" style="color: #605f5d">
<i></i>
<i></i>
<i></i>
<span>choose</span></a></div><span id="bms">BMS</span><span id="marketing">MARKETING</span>
<input type="search" name="key" id="key" value="" class="autosearch">
<input type="submit" name="submit" value="FIND">
</form>
</p>
</body>
【问题讨论】:
-
我想从 mysql 列中获取数据并在 jquery 中获取该数组以进行自动完成...请帮助我 ....
-
只是一个通知:考虑停止使用
mysql_,因为它已被弃用,并开始使用PDO或mysqli。