鉴于大家对PHP十分关注,我们编辑小组在此为大家搜集整理了“php+ajax做仿百度搜索 下拉自动提示框(有实例)”一文,供大家参考学习 !
php+mysql+ajax实现百度搜索下拉提示框 主要有3个文件三个文件在同一个目录里 如下图
下面是三个文件的代码 把sql文件导入到mysql数据库里 修改下数据库密码为自己的 记得哦是UTF-8编码
php+mysql+ajax实现百度搜索下拉提示框
效果图
rpc.php文件
复制代码 代码如下:
<?php
mysql_connect(''localhost'', ''root'' ,'''');
mysql_select_db("test");
$queryString =
php+ajax做仿百度搜索下拉自动提示框(有实例)_网学
php+ajax做仿百度搜索下拉自动提示框(有实例)
浏览:
POST[''queryString''];
if(strlen($queryString) >0) {
$sql= "SELECT value FROM countries WHERE value LIKE ''".$queryString."%'' LIMIT 10";
$query = mysql_query($sql);
while ($result = mysql_fetch_array($query,MYSQL_BOTH)){
$value=$result[''value''];
echo ''<li onClick="fill(\''''.$value.''\'');">''.$value.''</li>'';
}
}
?>
index.htm文件
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/uploadfile/201306/20/F9165939519.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</form>
</div>
</body>
</html>
sql数据库autoComplete.sql文件(导入到mysql)
复制代码 代码如下:
-- phpMyAdmin SQL Dump
-- version 3.3.5
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 12 月 09 日 02:36
-- 服务器版本: 5.0.22
-- PHP 版本: 5.2.14
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- 数据库: `test`
--
-- --------------------------------------------------------
--
-- 表的结构 `countries`
--
CREATE TABLE IF NOT EXISTS `countries` (
`id` int(6) NOT NULL auto_increment,
`value` varchar(250) NOT NULL default '''',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ;
--
-- 转存表中的数据 `countries`
--
INSERT INTO `countries` (`id`, `value`) VALUES
(1, ''Afghanistan''),
(2, ''Aringland Islands''),
(3, ''Albania''),
(4, ''Algeria''),
(5, ''American Samoa''),
(6, ''Andorra''),
(7, ''Angola''),
(8, ''Anguilla''),
(9, ''Antarctica''),
(10, ''Antigua and Barbuda''),
(11, ''Argentina''),
(12, ''Armenia''),
(13, ''Aruba''),
(14, ''Australia''),
(15, ''Austria''),
(16, ''Azerbaijan''),
(17, ''Bahamas''),
(18, ''Bahrain''),
(19, ''Bangladesh''),
(20, ''Barbados''),
(21, ''Belarus''),
(22, ''Belgium''),
(23, ''Belize''),
(24, ''Benin''),
(25, ''Bermuda''),
(26, ''Bhutan''),
(27, ''Bolivia''),
(28, ''Bosnia and Herzegovina''),
(29, ''Botswana''),
(30, ''Bouvet Island''),
(31, ''Brazil''),
(32, ''British Indian Ocean territory''),
(33, ''Brunei Darussalam''),
(34, ''Bulgaria''),
(35, ''Burkina Faso''),
(36, ''Burundi''),
(37, ''Cambodia''),
(38, ''Cameroon''),
(39, ''Canada''),
(40, ''Cape Verde''),
(41, ''Cayman Islands''),
(42, ''Central African Republic''),
(43, ''Chad''),
(44, ''Chile''),
(45, ''China''),
(46, ''Christmas Island''),
(47, ''Cocos (Keeling) Islands''),
(48, ''Colombia''),
(49, ''Comoros''),
(50, ''Congo''),
(51, ''Congo''),
(52, '' Democratic Republic''),
(53, ''Cook Islands''),
(54, ''Costa Rica''),
(55, ''Ivory Coast (Ivory Coast)''),
(56, ''Croatia (Hrvatska)''),
(57, ''Cuba''),
(58, ''Cyprus''),
(5