最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php+ajax 實現(xiàn)輸入讀取數(shù)據(jù)庫顯示匹配信息

 更新時間:2015年10月08日 11:58:09   作者:GaoAnLee  
這篇文章主要介紹了php+ajax 實現(xiàn)輸入讀取數(shù)據(jù)庫顯示匹配信息的相關(guān)資料,需要的朋友可以參考下

廢話不多說了,直接跟大家貼代碼了

dropbox_index.php

<!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=gb2312" />
<title>主搜索引擎下拉框自動顯示數(shù)據(jù)</title>
</head>
<script src="js/dropbox.js" type="text/javascript"></script>
<link href="css/dropbox.css" type="text/css" rel="stylesheet"/>
<body>
<form action="" method="post" enctype="multipart/form-data">
        <input name="txt" id="txt" class="txt" type="text" onkeyup ="showHint(this.value)" />    
        <input type="submit" class="btn" name="submit" value="Upload" /><br />
        <span id="txtHint" class="file-box"></span>
</form>
</body>
</html>

dropbox.js    ajax     

var xmlHttp
    function showHint(str)
    {
      if (str.length==0)
      { 
       document.getElementById("txtHint").innerHTML=""
       return
      }
      xmlHttp=GetXmlHttpObject()
      if (xmlHttp==null)
       {
         alert ("Browser does not support HTTP Request")
         return
       } 
      var url="responsepage.php"
      url=url+"?q="+str
      url=url+"&sid="+Math.random()
      xmlHttp.onreadystatechange=stateChanged 
      xmlHttp.open("GET",url,true)
      xmlHttp.send(null)
    }      
    //設(shè)置回調(diào)函數(shù)
    function stateChanged() 
    { 
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
       { 
        document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
       } 
    }
    function GetXmlHttpObject()
    {
      var xmlHttp=null;
      try
       {
         // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
      }
      catch (e)
      {
         // Internet Explorer
         try
         {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
       }
      return xmlHttp;
    }

dropbox.css

.txt{ height:22px; border:1px solid #cdcdcd; width:220px;border-right:none;}
.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:26px; width:70px;}

responsepage.php

<?php
  //get the q parameter from URL  
  $q=$_GET["q"];
  //全部小寫化
  $q=strtolower($q);
  //非空驗證
  if(isset($q) && $q != '')
  {
    $con = mysql_connect("localhost","root","lifu");
    if(!$con)
    {  
      die('Could not connect: ' .mysql_error());
    }
    mysql_select_db("my_db",$con);
    
    $sql = "select * from persons";
    //$sql="SELECT FirstName FROM Persons where Firstname like '%$q%'";
  
    $result =mysql_query($sql,$con);
    while($row = mysql_fetch_array($result))
     {
       //匹配判斷
       if(stristr(strtolower($row['FirstName']),$q))
       {
         //echo "-----------------Persons-----------------";
         echo /* "firstname:" .*/ $row['FirstName'] . "<br />";
         //echo "lastname:" . $row['LastName'] . "<br />";
         //echo "age:" . $row['Age'] . "<br />";
       }
       //echo $row['FirstName'] . "<br />";
     }
    mysql_close($con);
   }
?>

數(shù)據(jù)庫:


以上就是本文給大家介紹的php+ajax 實現(xiàn)輸入讀取數(shù)據(jù)庫顯示匹配信息的全部內(nèi)容,希望大家喜歡。

相關(guān)文章

最新評論

外汇| 太谷县| 连平县| 淮北市| 牙克石市| 阳西县| 容城县| 富平县| 肃宁县| 滨州市| 锡林郭勒盟| 英德市| 益阳市| 长顺县| 黔西| 长垣县| 渝中区| 浑源县| 东平县| 河曲县| 霍州市| 金阳县| 桃园市| 平顶山市| 油尖旺区| 禄丰县| 佛坪县| 神木县| 连平县| 石渠县| 汤原县| 神木县| 四平市| 合阳县| 林州市| 丰镇市| 罗江县| 霍邱县| 花莲市| 孝感市| 上林县|