我在网上找了一个样板,现在的主要问题是,输入第一个字符会从数据库里面查找,第二个字符以后就是获取的数据里面查找,请问怎么每次输入都直接从数据库里面查找
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ERP采购价格查询</title>
<link href="css/jquery.autocomplete.css" type=text/css rel=stylesheet><script src="js/jquery_s.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--<link rel="stylesheet" type="text/css" href="css/style.css" />--><style type="text/css">
 * {
  padding:0;
  margin:0;
 }
 body {
font-family:verdana;
font-size:12px;
margin-left: 0px;
margin-top: 0px;
 }
 .content {
  width:1100px;
  margin:20px 10px;
 }
 .content h1 {
  font-family:'΢ź';
  font-size:18px;
  padding-bottom:5px;
 }
 table {
  width:100%;
 }
 th, td {
  padding:6px 0;
  text-align:center;
 }
 th {
  background-color:#accdf4;
  color:#ffffff;
 }
 
 tr {
  background-color:#FFFFFE;
 }
 
 .odd {
  background-color:#FFFAFF;
 }
 
 .highlight {
  background-color:#E0E0E0;
}
.STYLE3 {font-size: 14px}
</style><script language="javascript">
$(document).ready(function() {
$("#keyword").autocomplete("getajaxtag.php",
{
delay:10,
             minChars:1,
             matchSubset:1,
             matchContains:1,
             cacheLength:10,
             onItemSelect:selectItem,
             onFindValue:findValue,
             formatItem:formatItem,
             autoFill:false
         }
     );
});
function findValue(li) {
     if( li = null ) return alert("No match!");
if( !!li.extra ) var sValue = li.extra[0];
else var sValue = li.selectValue;
}
function selectItem(li) { findValue(li);}
function formatItem(row) { return row[0];//return row[0] + " (id: " + row[1] + ")"//如果有其他参数调用row[1],对应输出格式Sparta|896
}
function lookupAjax(){
var oSuggest = $("#keyword")[0].autocompleter;
oSuggest.findValue();
return false;
}
</script></head><body><h2 class="top_title">ERP采购价格查询</h2><div class="content"><?PHPinclude_once ("conn.php");if(!empty($_POST['text']))
{
$text=$_POST['text'];
$item=$_POST['item'];
if($item=="item_code")
{
$item_code=$text;
}
else
{
$sql="SELECT `item_code` FROM `sku_rule` WHERE `$item`='$text'";
$querya = mysql_query($sql,$conn); 
$myaf = mysql_affected_rows();
if($myaf>0)
{
$resultaa= mysql_fetch_array($querya);
$item_code=$resultaa['item_code'];}
else
{
echo "<script>alert('没有查相关记录!');location.href='erp_price_find.php';</script>";
}
}
$sql_erp="SELECT * FROM `jperp`.`1_purch_order_details` WHERE `item_code`='$item_code'  order by `po_detail_item` desc";
$query_erp = mysql_query($sql_erp,$conn);
}
else
{
$sku_asin="";
$item_code="";
$sql_erp="select * from `jperp`.`1_purch_order_details` order by `po_detail_item` desc limit 50";
$query_erp = mysql_query($sql_erp,$conn);
}
?>  <a title="排序" href="sql.php?db=amazon_erp&amp;table=sku_rule&amp;sql_query=SELECT+%2A+FROM+%60sku_rule%60+ORDER+BY+%60sku_rule%60.%60delivery_areas%60+ASC&amp;token=5fc1c1e632ce608e822b537f4a6e1be4"></a>
<div id="opt">
<form id="formkeyword" name="formkeyword" method="post" action="erp_price_find.php">
  <input type="text" name="keyword" size="40" maxlength="255" value="" id="keyword" class="text" />
  </input>
<input type="submit" class="btn" id="find_btn" value="搜 索" />
    </form>
    
</div>
<table width="49%" cellspacing="1" bgcolor="#0093C4">
   <thead>
     <tr>
       
       <th width="8%" class="STYLE3">SKU/ASIN</th>
       <th width="12%" class="STYLE3">Item Code</th>
   <th width="23%" class="STYLE3">Description </th>
       <th width="12%" class="STYLE3">Delivery_date</th>
       <th width="11%" class="STYLE3">Unit_price</th>
   <th width="8%" class="STYLE3">Act_price</th>
       <th width="13%" class="STYLE3">Quantity_ordered</th>
       <th width="13%" class="STYLE3">Quantity_received</th>
     </tr>
   </thead>
   <tbody>
     <?PHP
  while($row = mysql_fetch_array($query_erp, MYSQL_ASSOC)) {
  ?>
     <tr>
       
       <td><?PHP if(!empty($text))
   {
   echo $text; 
   }
  
   ?></td>
       <td><?PHP echo $row['item_code']; ?></td>
   <td><?PHP echo $row['description']; ?></td>
       <td><?PHP echo $row['delivery_date']; ?></td>
       <td><?PHP  echo $row['unit_price'];  ?>    </td>
    <td><?PHP echo $row['act_price'] ?></td>
        <td><?PHP echo $row['quantity_ordered'] ?></td>
        <td><?PHP echo $row['quantity_received'] ?></td>
     </tr>
     <?PHP
  }
  ?>
   </tbody>
 </table>
 
</div></body>
</html>

解决方案 »

  1.   

    cacheLength:10,这个改为   cacheLength:0,             
      

  2.   


    <label for="search1">search</label><input id="search1" type="search" name="search" list="slist" />
    <datalist id="slist">
            <option value="http://www.google.com" label="Google" />
            <option value="http://www.yahoo.com" label="Yahoo" />
            <option value="http://www.bing.com" label="Bing" />
    </datalist>使用chrome浏览器看看