This article mainly introduces the Php+ajax real-time input automatic search matching method, the interested friend's reference, hoped to have the help to everybody.
dropbox_index.php
<! DOCTYPE html>
dropbox.js Ajax
var xmlHttp function Showhint (str) {if (str.length==0) {document.getElementById ("Txthint"). Innerh Tml= "" Return} xmlhttp=getxmlhttpobject () if (xmlhttp==null) {alert ("Browser does no T 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 (nul L)}//Set callback function StateChanged () {if (xmlhttp.readystate==4 | | xmlhttp.readystate== "complet E ") {document.getElementById (" Txthint "). Innerhtml=xmlhttp.responsetext}} function Getxmlhtt Pobject () {var xmlhttp=null; try {//Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest (); } catch (E) {///Internet Explorer try {xmlhttp=new ActiveXObject ("Msxml2.xmlh TTP "); } 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"]; All lowercase $q =strtolower ($q); Non-null validation 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)) { //Match to determine 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); }? >
Database:
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
Functions of the ziparchive function in PHP
How PHP can serialize and deserialize data
How PHP Gets the operating system type