宝哥软件园

php ajax实现输入读取数据库显示匹配信息

编辑:宝哥软件园 来源:互联网 时间:2021-10-01

废话不多说了,直接跟大家贴代码了

dropbox_index.php

!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。org/TR/XHTML 1/DTD/XHTML 1-Transitional。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' hearteta http-equiv=' Content-Type ' Content=' text/html;字符集=GB 2312/标题主搜索引擎下拉框自动显示数据/title/head脚本src=' http : js/Dropbox。js ' type=' text/JavaScript '/script link href=' CSS/Dropbox。' CSS '类型=' text/CSS ' rel='样式表/body form action=' method=' post ' enctype=' multipart/form-data '输入名称=' txt ' id=' txt ' class=' txt ' type=' text ' on key up=' show hint(这。值)'/输入类型

var xmlHttp函数show hint(str){ if(str。长度==0){文档。getelementbyid(' TxThinT ').innerHTML=' return } XMlhttp=GetXMlhttpObject()if(XMlhttp==null){ alert('浏览器不支持HTTP请求)返回{ var URL='响应页面。PHP ' URL=URL?q=' str url=URL ' sid=' math。随机()。xmlhttp。onreadystatechange=状态已更改的XMlhttp。open(' GET ',URL,true) xmlHttp.send(null) } //设置回调函数函数状态已更改(){ if(xmlhttp。readystate==4 | | xmlhttp。ready state==' complete '){ document。getelementbyid(' txtHint ').innerHTML=xmlHttp。responsetext } }函数GetXmlHttpObject(){ var xmlHttp=null;试试{ //火狐,Opera 8.0,Safari xmlHttp=new XMLHttpRequest();} catch (e) { //Internet Explorer尝试{ xmlHttp=新的ActiveX对象(' Msxml 2 .XMLHTTP’);} catch(e){ xmlHttp=新ActiveX对象(' Microsoft .XMLHTTP’);} }返回xmlHttp}dropbox.css。txt { height :22 pxborder :1 px固体# cdcdcdcd宽度width :220 pxborder-right :无;} .FFF;border:1px固体# CDCDCDCD高度:26 px宽度:70 px}

responsepage.php

?PHP//从URL $q=$_GET['q']获取q参数;//全部小写化$ q=strtolow($ q);//非空验证if(isset($q) $q!=' '){ $ con=MySQL _ connect(' localhost ',' root ',' liff ');if(!$con) { die('无法连接: '。MySQL _ error());} mysql_select_db('my_db ',$ con);$sql='从人员中选择* ';//$ SQL='从人员中选择名字,其中西方人名的第一个字像“% $ q %”;$result=mysql_query($sql,$ con);while($ row=MySQL _ fetch _ array($ result)){//匹配判断if(stristr(strtolow($ row['名字']),$ q)){//echo '-Persons-';echo/*“名字:”.*/$row['FirstName'].br/';//回显lastname:$row['LastName'].br/';//echo 'age:$row['Age'].br/';} //echo $row['FirstName'].br/';} MySQL _ close($ con);}?数据库:

以上就是本文给大家介绍的php ajax实现输入读取数据库显示匹配信息的全部内容,希望大家喜欢。

更多资讯
游戏推荐
更多+