K9 通用版 博客版 主题版 地方门户版 企业版 |   企业(ASP) 分类 使用 分享 疑问 模板 建议 帮助 错误 其他
+新建主题 [Ajax]
填写帐号密码即可完成注册
+新建话题 最新回复排序 最新主题排序 精华帖子

php搜索自动提示功能——autoComplete

123Next >

updatex 发表于:10-09-02 15:44 [添加收藏] 楼主 [回复] #Top#
updatex 人气:1518 积分:1551 金币:32240
VIP KC元老 灌水狂人
php搜索自动提示功能——autoComplete[图1]

点击下载


文档结构:
root——auto——auto.html
                   ├—get_keyword.php
                   ├—jquery.js
                   ├—jquery.autocomplete.js
                   ├—jquery.autocomplete.css
                   └—indicator.gif


auto.html
  1. <script type="text/javascript" src="jquery.js"></script>
  2. <script type="text/javascript" src="jquery.autocomplete.js"></script>
  3. <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
  4. <title>搜索自动提示</title>
  5. </head>
  6. <body>
  7. <form name="form1" method="get" action="../search.php">
  8. <input type="text" name="query" id="search" size="30" autocomplete="off" />
  9. <input type="submit" name="bt_submit" value="给我搜" />
  10. </form>
  11. <script type="text/javascript">
  12. $().ready(function() {
  13. $("#search").autocomplete("get_keyword.php", {
  14. width: 260,
  15. matchContains: true,
  16. selectFirst: false
  17. });
  18. });
  19. </script>
复制代码
get_keyword.php
  1. <?PHP
  2. $mysql_server_name = "localhost";//数据库服务器
  3. $mysql_username    = "root";//数据库用户名
  4. $mysql_password    = "root";//数据库密码
  5. $mysql_database    = "kc";//数据库名

  6. mysql_connect( $mysql_server_name, $mysql_username, $mysql_password ) 
  7. or die("database communication failed");
  8. mysql_query("SET character_set_connection='utf8', character_set_results='utf8', character_set_client=binary");//本例中使用utf-8编码,gb3212未测试,可能会出现乱码
  9. mysql_select_db($mysql_database);

  10. $part = $_GET['s'];
  11. $query = "SELECT ktitle FROM `king__article` WHERE ktitle LIKE '%$part%' ";//SQL语句,本例中是从king__article表中取出标题中包含$part的数据
  12. $result = mysql_query($query);


  13. $rownumber = mysql_num_rows($result);
  14. if( $rownumber > 0 )
  15. {
  16. while( $row = mysql_fetch_array($result) )
  17. {
  18.   echo  $row["ktitle"]."n";
  19. }
  20. }
  21. ?>
复制代码
仅作参考,欢迎交流
KingCMS.Info 发表于:10-09-04 15:12 沙发 [回复] #Top#
KingCMS.Info 人气:34 积分:85 金币:952
微笑支持一下,感觉不错。
hnce 发表于:10-09-21 06:47 板凳 [回复] #Top#
hnce 人气:0 积分:0 金币:0
这个东西怎么样咯
ahao303 发表于:10-09-22 17:14 4楼 [回复] #Top#
ahao303 人气:152 积分:1877 金币:10882
KC元老
有没有毒副作用呢?
poyiku 发表于:10-10-02 21:40 5楼 [回复] #Top#
poyiku 人气:0 积分:4 金币:40
看起来不错哦
Brahma 发表于:10-10-08 17:23 6楼 [回复] #Top#
Brahma 人气:97 积分:1216 金币:4418
KC元老
这个不错.搜藏
iitding 发表于:10-10-12 10:11 7楼 [回复] #Top#
iitding 人气:582 积分:1 金币:18324
最佳新人 灌水狂人
收藏备用··
lowpower 发表于:11-04-23 10:19 8楼 [回复] #Top#
lowpower 人气:11 积分:420 金币:1139
先收起来再说,谢谢楼主提供
wuchunkai 发表于:11-04-23 11:01 9楼 [回复] #Top#
wuchunkai 人气:472 积分:6 金币:19338
VIP KC元老 灌水狂人
这个很不错的说。试试看。
wuchunkai 发表于:11-10-22 15:55 10楼 [回复] #Top#
wuchunkai 人气:472 积分:6 金币:19338
VIP KC元老 灌水狂人
这个还是有问题。测试了不理想!!

123Next >

发表回复

帐号 匿名发布 审核后可见 [加载完整在线编辑器]
内容
验证码
KingCMS 内容管理系统

关于我们 联系我们 广告报价 付款方式 站点导航

Copyright © 2004-2015 Focuznet All rights reserved.

广州唯众网络科技有限公司 粤ICP备08008106号