php随笔2-php+ajax 实现输入读取数据库显示匹配信息
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>主搜索引擎下拉框自动显示数据</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)
} //设置回调函数
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);
}
?>
数据库:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAABHCAIAAACLT2tHAAALOUlEQVR4nO2d3U4bSRbHz/NMrkGFHyHhDVZKkJux1hEPsRdhGGyPsLQvsIkUKROk0MwqXi1OpEirlTaZGS7AcLGWJiHmY2ZJgk3ADaYb70VXdVX1hxu3jcvtOn+dC1PV3VT965xfVzeEwPc/HzesLoYY3/983EXdWKenp6qHkCbpadfp6ak3cUDoIHQGlJ5VlFh62oXQQegMU3pWUWLpaRdCB6EzTLVaLdVDSJP0tKvVankTR+ggdAaVnlWUWHra1Wq1ms2m+xmhg9AZVHpWUWLpaRdCB6EzTHnJhLqJ9LSr2WyenJy4nxE6CJ1BpWcVJZaedrnQsW2nO87QeWIAAPzJ7Das+l8I+EXK/xo1dCo5eQi5ituYq/RhfiXHzqSqlzP9XWHs5N3BZFVykCnXB7y2PnZ1u113uoObNo46OTnh0MlXG68/d8cwlh4AANz7sfv6c/3hlPe5+/pz9/WPbvlnHv5yK986X21cXdnWRUeOnwyYN/2NN4udHwg99ycDAGCmuBPsSmXYtnP0+/8i7BKmiXbF2NWxLjqmAQBASrvKx3kbsz44PLJtp21dphM6n7tPFjMAAA8qKYTOTLE0D+SHmr8rlWHbztHvf9wmdDSxK2yykxLurHtDp3LP/zCTW3K7finfCWmXj39QcXnBxPYjvnOnyk/Cvxc9vjd02NXYwIYNnc6V3bYu5VjPwrwZ1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R6jAJ/j0DCAAoQICECogAKECAhAqIAChAgIQKiAAoQICECogAKECAhAqIMB/MmJ5+x0RcJ4AAAAASUVORK5CYII=" alt="" />
php随笔2-php+ajax 实现输入读取数据库显示匹配信息的更多相关文章
- spring读取数据库的配置信息(url、username、password)时的<bean>PropertyPlaceholderConfigurer的用法
用法1: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...
- JSP 实现 之 读取数据库显示图片
用JSP从数据库中读取图片并显示在网页上 环境mysql+tomcat: <1>先在mysql下建立如下的table. 并insert图像. mysql.sql文件如下: ) unsign ...
- ajax处理级联访问数据库显示
首先创建简单的html页面,写出如下代码: 静态页相关代码: js代码:
- JMeter接口测试-循环读取库的用户信息
前言 如何实现循环读取数据库的用户信息,并传递到下一个登录请求呢,下面我们一起来学习吧!在之前我们已经学会了利用JMeter连接数据库了,具体操作可以看我之前的随笔JMeter接口测试-JDBC测试 ...
- C# 保存PictureBox中的图片到数据库,并从数据库读取图片显示到PictrueBox,解决报错 “无效参数”
下面是两段关键代码: /// <summary> /// 将一张图片转换为字节 /// </summary> /// <param name="img" ...
- android键盘输入读取
android键盘输入读取 监控android键盘输入方式有两种,一种在java层实现,重写onKeyDown和onKeyUp方法.另一种是在jni层实现,监控/dev/input/event0键盘 ...
- VS2010中使用Jquery调用Wcf服务读取数据库记录
VS2010中使用Jquery调用Wcf服务读取数据库记录 开发环境:Window Servere 2008 +SQL SERVE 2008 R2+ IIS7 +VS2010+Jquery1.3.2 ...
- 如何用ajax写分页查询(以留言信息为例)-----2017-05-17
要写分页,首先你得清楚,一页你想显示多少条信息?如何计算总共显示的页数? 先说一下思路: (1)从数据库读取数据,以chenai表为例,读取所有留言信息.并能够实现输入发送者,可以查询该发送者的留言总 ...
- 《python核心编程》笔记——文件的创建、读取和显示
创建文件(makeTextFile.py)脚本提醒用户输入一个尚不存在的文件名,然后由用户输入文件每一行,最后将所有文本写入文本文件 #!/usr/bin/env python 'makeTextFi ...
随机推荐
- php之Cookie与Session详解
Cookie管理 Cookie是在HTTP协议下,通过服务器或脚本语言可以维护客户浏览器上信息的一种方式,Cookie的使用很普遍,许多提供个人化服务的网站都是利用Cookie来区别不同用户,以显示与 ...
- Android EditText 取消复制粘贴功能,取消横向全屏编辑功能(一)
在做一些安全性的软件时候常常要考虑取消 EditText 上的复制粘贴功能以确保安全性.下面就记录了这个方法: 首先在API-11以下的版本很简单,只需要在Xml布局文件或者用代码把长按属性设置成fa ...
- grep 和 perl多个条件匹配
grep和perl多个条件匹配使用‘|’作为分割符号 grep -E 'abc|def' perl if(/abc|def/)
- a 标签的四个伪类
link 有链接属性时visited 链接地址已被访问过active 被用户激活(在鼠标点击与释放之间发生的事件)hover 其鼠标悬停 <!DOCTYPE ...
- php 垃圾回收机制----写时复制和引用计数
PHP使用引用计数和写时复制来管理内存.写时复制保证了变量间复制值不浪费内存,引用计数保证了当变量不再需要时,将内存释放给操作系统. 要理解PHP内存管理,首先要理解一个概念----符号表. 符号表的 ...
- webstrom 常用快捷键
最近在学习javascript,同时发现了一款非常好用的IDE webstrom 现在记录改IDE的快捷键 1. ctrl + shift + n: 打开工程中的文件,目的是打开当前工程下任意目录的文 ...
- 矩阵转置 O(1)空间
题目:用O(1)的空间实现矩阵的转置 为了方便,使用一维数组来分析.所谓矩阵转置,行变列,列变行.在转置的过程中,有的元素位置是不变的:对于变化位置的元素,要求O(1)空间完成,那么这些位置的变化一定 ...
- structs常用的Action
今天座右铭-----谦虚使人进步,骄傲使人落后. 除了基本的Action之外,structs还提供几个其他的类型Action,下面就简单的说一下: 1.DispatchAction:能同时完成多个Ac ...
- 京东区块排版负margin用法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python学习入门基础教程(learning Python)--8.3 字典常用的方法函数介绍
本节的主要讨论内容是有关dict字典的一些常用的方法函数的使用和范例展示. 1. clear清除字典数据 语法结构如下: dict_obj.clear() 示例代码如下: dict1 = {'web' ...