search
Homephp教程php手册php+ajax做仿百度搜索下拉自动提示框(有实例)
php+ajax做仿百度搜索下拉自动提示框(有实例)Jun 13, 2016 am 11:59 AM
php+ajaxdrop downExampleaccomplishhintsearchhaveBaiduautomatic

php+mysql+ajax实现百度搜索下拉提示框 主要有3个文件三个文件在同一个目录里 如下图

下面是三个文件的代码 把sql文件导入到mysql数据库里 修改下数据库密码为自己的 记得哦是UTF-8编码

php+mysql+ajax实现百度搜索下拉提示框
效果图

rpc.php文件

复制代码 代码如下:


mysql_connect('localhost', 'root' ,'');
mysql_select_db("test");
$queryString = $_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 '

  • '.$value.'
  • ';
    }
    }
    ?>

    index.htm文件

    复制代码 代码如下:






    Ajax Auto Suggest








    Type your county:










    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'),
    (59, 'Czech Republic'),
    (60, 'Denmark'),
    (61, 'Djibouti'),
    (62, 'Dominica'),
    (63, 'Dominican Republic'),
    (64, 'East Timor'),
    (65, 'Ecuador'),
    (66, 'Egypt'),
    (67, 'El Salvador'),
    (68, 'Equatorial Guinea'),
    (69, 'Eritrea'),
    (70, 'Estonia'),
    (71, 'Ethiopia'),
    (72, 'Falkland Islands'),
    (73, 'Faroe Islands'),
    (74, 'Fiji'),
    (75, 'Finland'),
    (76, 'France'),
    (77, 'French Guiana'),
    (78, 'French Polynesia'),
    (79, 'French Southern Territories'),
    (80, 'Gabon'),
    (81, 'Gambia'),
    (82, 'Georgia'),
    (83, 'Germany'),
    (84, 'Ghana'),
    (85, 'Gibraltar'),
    (86, 'Greece'),
    (87, 'Greenland'),
    (88, 'Grenada'),
    (89, 'Guadeloupe'),
    (90, 'Guam'),
    (91, 'Guatemala'),
    (92, 'Guinea'),
    (93, 'Guinea-Bissau'),
    (94, 'Guyana'),
    (95, 'Haiti'),
    (96, 'Heard and McDonald Islands'),
    (97, 'Honduras'),
    (98, 'Hong Kong'),
    (99, 'Hungary'),
    (100, 'Iceland'),
    (101, 'India'),
    (102, 'Indonesia'),
    (103, 'Iran'),
    (104, 'Iraq'),
    (105, 'Ireland'),
    (106, 'Israel'),
    (107, 'Italy'),
    (108, 'Jamaica'),
    (109, 'Japan'),
    (110, 'Jordan'),
    (111, 'Kazakhstan'),
    (112, 'Kenya'),
    (113, 'Kiribati'),
    (114, 'Korea (north)'),
    (115, 'Korea (south)'),
    (116, 'Kuwait'),
    (117, 'Kyrgyzstan'),
    (118, 'Lao People''s Democratic Republic'),
    (119, 'Latvia'),
    (120, 'Lebanon'),
    (121, 'Lesotho'),
    (122, 'Liberia'),
    (123, 'Libyan Arab Jamahiriya'),
    (124, 'Liechtenstein'),
    (125, 'Lithuania'),
    (126, 'Luxembourg'),
    (127, 'Macao'),
    (128, 'Macedonia'),
    (129, 'Madagascar'),
    (130, 'Malawi'),
    (131, 'Malaysia'),
    (132, 'Maldives'),
    (133, 'Mali'),
    (134, 'Malta'),
    (135, 'Marshall Islands'),
    (136, 'Martinique'),
    (137, 'Mauritania'),
    (138, 'Mauritius'),
    (139, 'Mayotte'),
    (140, 'Mexico'),
    (141, 'Micronesia'),
    (142, 'Moldova'),
    (143, 'Monaco'),
    (144, 'Mongolia'),
    (145, 'Montserrat'),
    (146, 'Morocco'),
    (147, 'Mozambique'),
    (148, 'Myanmar'),
    (149, 'Namibia'),
    (150, 'Nauru'),
    (151, 'Nepal'),
    (152, 'Netherlands'),
    (153, 'Netherlands Antilles'),
    (154, 'New Caledonia'),
    (155, 'New Zealand'),
    (156, 'Nicaragua'),
    (157, 'Niger'),
    (158, 'Nigeria'),
    (159, 'Niue'),
    (160, 'Norfolk Island'),
    (161, 'Northern Mariana Islands'),
    (162, 'Norway'),
    (163, 'Oman'),
    (164, 'Pakistan'),
    (165, 'Palau'),
    (166, 'Palestinian Territories'),
    (167, 'Panama'),
    (168, 'Papua New Guinea'),
    (169, 'Paraguay'),
    (170, 'Peru'),
    (171, 'Philippines'),
    (172, 'Pitcairn'),
    (173, 'Poland'),
    (174, 'Portugal'),
    (175, 'Puerto Rico'),
    (176, 'Qatar'),
    (177, 'Runion'),
    (178, 'Romania'),
    (179, 'Russian Federation'),
    (180, 'Rwanda'),
    (181, 'Saint Helena'),
    (182, 'Saint Kitts and Nevis'),
    (183, 'Saint Lucia'),
    (184, 'Saint Pierre and Miquelon'),
    (185, 'Saint Vincent and the Grenadines'),
    (186, 'Samoa'),
    (187, 'San Marino'),
    (188, 'Sao Tome and Principe'),
    (189, 'Saudi Arabia'),
    (190, 'Senegal'),
    (191, 'Serbia and Montenegro'),
    (192, 'Seychelles'),
    (193, 'Sierra Leone'),
    (194, 'Singapore'),
    (195, 'Slovakia'),
    (196, 'Slovenia'),
    (197, 'Solomon Islands'),
    (198, 'Somalia'),
    (199, 'South Africa'),
    (200, 'South Georgia and the South Sandwich Islands'),
    (201, 'Spain'),
    (202, 'Sri Lanka'),
    (203, 'Sudan'),
    (204, 'Suriname'),
    (205, 'Svalbard and Jan Mayen Islands'),
    (206, 'Swaziland'),
    (207, 'Sweden'),
    (208, 'Switzerland'),
    (209, 'Syria'),
    (210, 'Taiwan'),
    (211, 'Tajikistan'),
    (212, 'Tanzania'),
    (213, 'Thailand'),
    (214, 'Togo'),
    (215, 'Tokelau'),
    (216, 'Tonga'),
    (217, 'Trinidad and Tobago'),
    (218, 'Tunisia'),
    (219, 'Turkey'),
    (220, 'Turkmenistan'),
    (221, 'Turks and Caicos Islands'),
    (222, 'Tuvalu'),
    (223, 'Uganda'),
    (224, 'Ukraine'),
    (225, 'United Arab Emirates'),
    (226, 'United Kingdom'),
    (227, 'United States of America'),
    (228, 'Uruguay'),
    (229, 'Uzbekistan'),
    (230, 'Vanuatu'),
    (231, 'Vatican City'),
    (232, 'Venezuela'),
    (233, 'Vietnam'),
    (234, 'Virgin Islands (British)'),
    (235, 'Virgin Islands (US)'),
    (236, 'Wallis and Futuna Islands'),
    (237, 'Western Sahara'),
    (238, 'Yemen'),
    (239, 'Zaire'),
    (240, 'Zambia'),
    (241, 'Zimbabwe');


    你在本地服务器测试下 一定很给力 而且原理很简单 没那么麻烦
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    百度开源消息中间件BifroMQ,支持高性能物联网连接和消息处理百度开源消息中间件BifroMQ,支持高性能物联网连接和消息处理Jul 15, 2023 pm 08:33 PM

    7月14日消息,百度昨日宣布开源其旗下的MQTTBroker消息中间件BifroMQ,该消息中间件是由Java实现,具有高性能和分布式的特点。据称,BifroMQ是百度智能云物联网核心套件IoTCore的基础技术之一。BifroMQ采用了Serverless架构,并且无缝集成了原生的多租户支持。该消息中间件源自百度物联网团队多年的技术积累,旨在支持构建大规模的物联网设备连接和消息系统。据小编了解,BifroMQ采用了负载独立子集群设计,可以高效处理连接会话、消息转发和消息存储等工作负载。各子集群

    PHP实现对接百度智能分类接口的简单指南PHP实现对接百度智能分类接口的简单指南Aug 13, 2023 pm 12:13 PM

    PHP实现对接百度智能分类接口的简单指南近年来,随着人工智能的快速发展,智能分类技术被广泛应用于许多领域。百度智能分类接口就是其中一种应用,它可以根据传入的文本数据对其进行分类,帮助我们更好地理解文本的内容。本文将介绍如何使用PHP语言对接百度智能分类接口,并给出相应的代码示例。一、准备工作注册百度开发者账号并登录。创建一个应用并获取应用的APIKey和S

    PHP实现对接百度语音识别接口的步骤与注意事项PHP实现对接百度语音识别接口的步骤与注意事项Aug 13, 2023 pm 01:57 PM

    PHP实现对接百度语音识别接口的步骤与注意事项前言:随着人工智能技术的快速发展,语音识别技术也逐渐成熟并被广泛应用。百度语音识别接口是一款强大的云端语音识别服务,提供丰富的功能和灵活的配置选项,方便开发者根据自己的需求进行定制化开发。本文将利用PHP语言来实现对接百度语音识别接口的操作步骤,并对注意事项进行详细介绍。步骤一:申请百度语音识别接口首先,我们需要

    百度网盘崩溃问题已解决并致歉:现已修复,请用户尝试重新登录百度网盘崩溃问题已解决并致歉:现已修复,请用户尝试重新登录Aug 10, 2023 pm 02:25 PM

    据本站8月9日16时许报道,百度旗下产品出现了大规模故障,例如百度网盘在使用过程中出现了视频播放失败的情况,其他业务也有用户反映无法打开或崩溃的现象。经过本站的调查,发现是由于百度CDN服务异常所致百度网盘回应称,对此问题十分抱歉并正在紧急修复中,请耐心等待,感谢您的理解五分钟后,百度网盘回复说问题已解决,请您尝试重新登录,感谢您的支持CDN(内容分发网络)通过将源站内容分发至全球各地的加速节点,使用户在请求网站资源时能够被调度至距离最近的加速节点,从而直接获得所需内容,提高用户对网站资源的访问

    PHP如何对接百度文心一言接口?PHP如何对接百度文心一言接口?Aug 13, 2023 pm 09:27 PM

    PHP如何对接百度文心一言接口?百度文心一言接口是一个提供随机返回一句文心话的接口,使用起来非常简单。本文将介绍PHP如何对接百度文心一言接口,并提供代码示例。首先,我们需要申请百度文心一言接口的访问权限。在百度开放平台上创建一个应用,并获取到相应的APIKey。接下来,我们可以使用PHP中的cURL库来发送HTTP请求并获取接口返回的数据。下面是一个简单

    Python与百度智能语音接口对接的实践经验与技巧分享Python与百度智能语音接口对接的实践经验与技巧分享Aug 13, 2023 pm 12:24 PM

    Python与百度智能语音接口对接的实践经验与技巧分享一、引言百度智能语音接口是一种强大的语音识别技术,可以将语音转化为对应的文字,并且支持多种场景下的语音输入,如麦克风输入、文件输入等。在实际开发中,与百度智能语音接口进行对接可以帮助我们实现语音识别、语音转写等功能。本文将分享一些Python与百度智能语音接口对接的实践经验与技巧,并提供代码示例供参考。二

    Python与百度AI接口对接的基础入门指南Python与百度AI接口对接的基础入门指南Aug 12, 2023 am 11:45 AM

    Python与百度AI接口对接的基础入门指南引言:随着人工智能技术的快速发展,百度AI的接口提供了许多强大的功能和服务。Python作为一种功能强大且易于学习的编程语言,与百度AI的接口对接特别方便。本文将介绍一些常见的百度AI接口,并提供相应的Python代码示例,帮助读者快速入门。一、百度语音识别接口:百度语音识别接口可以用于将语音转换为文本,实现语音识

    使用Python实现百度图像识别API对接教程使用Python实现百度图像识别API对接教程Aug 12, 2023 pm 07:58 PM

    使用Python实现百度图像识别API对接教程一、介绍随着人工智能的发展,图像识别技术已广泛应用于各个领域。而百度图像识别API是一款强大而易用的图像识别工具,可以帮助开发者快速实现图像分类、物体检测、图像搜索等功能。本文将详细介绍如何使用Python语言对接百度图像识别API,并给出代码示例。二、准备工作注册百度云账号首先,你需要在百度云官网注册一个账号,

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    VSCode Windows 64-bit Download

    VSCode Windows 64-bit Download

    A free and powerful IDE editor launched by Microsoft

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version