<?php
//* Ajax快速搜索结果程序 - Ajax Quick Search Results
//* Copyright 2008 - 2010 闻泰网络
//* http://www.weentech.com
$minimum_length = 3; // 在搜索输入框中键入多少个字符后,开始进行Ajax查询. 要求和ajax_search.js文件中的设置的值保持一致
$result_limits = 6; // 当搜索结果数量大于此数目时,快速结果显示框底部显示“更多搜索结果”的图片和链接
$search_mode = 'OR'; // 设置为 'OR' 表示只要匹配一个关键词,设置为 'AND' 表示要匹配所有关键词
$rootpath = './../'; // 网站的根目录
if (isset($_GET['ween_search_query']) && strlen($_GET['ween_search_query']) >= 3) {
$search_keywords = sqlsafefilter($_REQUEST['ween_search_query']);
}else{
exit();
}
//以下是两个函数
function EscapeEntity($string)
{
return str_replace(array('&', '"', '<', '>'), array( '&','"', '<', '>'), $string);
}
// sqlsafefilter()函数过滤非法的MYSQL查询,这里比较严格,可根据自己的需要删减过滤的字符
function sqlsafefilter( $source )
{
$entities_match = array(',',';','$','!','@','#','%','^','&','*','_','(',')','+','{','}','|',':','"','<','>','?','[',']','\\',"'",'.','/','*','+','~','`','=');
$entities_replace = array(' ',' ','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
return str_replace($entities_match, $entities_replace, trim($source));
}
// 以下搜索代码是示例,需要根据自己的网站系统所使用的数据库查询函数等定制
if(file_exists($rootpath . 'includes/core.php')){
define('IN_WEENCOMPANY', true);
if(isset($_GET['lang']) AND (!isset($_COOKIE['weenCompany_forelang']) OR $_COOKIE['weenCompany_forelang'] != $_GET['lang']))
{
$lang = strtolower($_GET['lang']);
if($lang == 'cn' OR $lang == 'en'){
setcookie("weenCompany_forelang", $lang, 0, "/");
Header("Location: $_SERVER[REQUEST_URI]");
exit();
}
}
include($rootpath . 'includes/core.php');
if($sitedefaultlang == 'en')
{
$forelang='en';
}else{
$forelang='cn';
}
$keywords = explode (' ', $search_keywords);
if(strtoupper($search_mode) == 'OR'){
$boolean_type = 'OR';
}else{
$boolean_type = 'AND';
}
$query_where .= '(';
foreach ($keywords as $key => $value)
{
$query_where .= " (title LIKE '%".$value."%' OR description LIKE '%".$value."%' OR specification LIKE '%".$value."%' OR priceship LIKE '%".$value."%') " . $boolean_type;
}
unset ($keywords);
$query_where = rtrim ($query_where, ' ' . $boolean_type);
$query_where .= ')';
$get_datas = $DB->query("SELECT imageid, title, images, price, rating FROM " . TABLE_PREFIX . "m17_products
WHERE activated = '1' AND ".$query_where."
ORDER BY datecreated DESC
LIMIT " . ($result_limits + 1) . ""); //($result_limits + 1)表示只搜索比限制的多一个就可以了,搜索多了也不显示
$search_counts = $DB->get_num_rows($get_datas);
if ($search_counts <1) {
exit();
}
$view_all = '';
if ($search_counts > $result_limits) {
$view_all = sprintf(' view_all="%s"', EscapeEntity(sprintf('<a href="%ssearch.php?ween_search_query=%s">%s</a>', $rootpath, $search_keywords, '.')));
}
echo '<?xml version="1.0"?>'."\n";
echo sprintf('<results type="%s" result_count="%s"%s>'."\n", '快速搜索结果:', $search_counts, $view_all);
while($data = $DB->fetch_array($get_datas))
{
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity($data['title']), EscapeEntity(sprintf('价格: %s元', $data['price'])), EscapeEntity('show.php?id='.$data['imageid']), EscapeEntity('images/'.$data['images']), EscapeEntity(sprintf('images/IcoRating%s.gif', int($data['rating']))));
}
echo "</results>\n";
exit();
}
// 以上搜索代码需要根据自己的网站系统所使用的数据库查询函数等定制
// 以下代码是显示测试数据,无实际用途,当使用上面的实际搜索代码时,以下代码需要删除
$view_all = '';
$search_counts = 7;
if ($search_counts > $result_limits) {
$view_all = sprintf(' view_all="%s"', EscapeEntity(sprintf('<a href="%ssearch.php?ween_search_query=%s">%s</a>', $rootpath, $search_keywords, '.')));
}
echo '<?xml version="1.0"?>'."\n";
echo sprintf('<results type="%s" result_count="%s"%s>'."\n", '快速搜索结果:', 118, $view_all);
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('weenCompany 中英文闻名企业网站系统'), EscapeEntity('价格: 380元'), EscapeEntity('show.php?id=3'), EscapeEntity('images/s3.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 2)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween MP4高级播放器'), EscapeEntity('价格: 11元'), EscapeEntity('show.php?id=1'), EscapeEntity('images/s1.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 0)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween P8商用笔记本电脑'), EscapeEntity('价格: 1220元'), EscapeEntity('show.php?id=2'), EscapeEntity('images/s2.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 1)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween 高级电脑背包'), EscapeEntity('价格: 96元'), EscapeEntity('show.php?id=4'), EscapeEntity('images/s4.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 3)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween 高保真耳麦'), EscapeEntity('价格: 127元'), EscapeEntity('show.php?id=5'), EscapeEntity('images/s5.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 4)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween 宽屏笔记本电脑'), EscapeEntity('价格: 9680元'), EscapeEntity('show.php?id=6'), EscapeEntity('images/s6.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 5)));
echo sprintf('<result title="%s" price="%s" url="%s" image="%s" ratingimg="%s" />'."\n", EscapeEntity('ween MP3播放器'), EscapeEntity('价格: 780元'), EscapeEntity('show.php?id=7'), EscapeEntity('images/s7.jpg'), EscapeEntity(sprintf('images/IcoRating%s.gif', 5)));
echo "</results>\n";
// 以上代码是显示测试数据,无实际用途,当使用上面的实际搜索代码时,以上代码需要删除
?>
没有合适的资源?快使用搜索试试~ 我知道了~
Ajax快速显示搜索结果程序
共21个文件
gif:9个
jpg:7个
js:2个
需积分: 9 9 下载量 33 浏览量
2010-10-09
17:32:19
上传
评论
收藏 46KB RAR 举报
温馨提示
此程序实现当用户在搜索框中输入内容时,可快速显示搜索结果的功能。默认是PHP程序,用户完可以移植到非PHP网站系统中。
资源推荐
资源详情
资源评论
收起资源包目录
Ajax快速显示搜索结果程序.rar (21个子文件)
images
s2.jpg 1KB
s4.jpg 3KB
IcoRating5.gif 751B
s3.jpg 3KB
s1.jpg 3KB
IcoRating3.gif 1KB
s7.jpg 747B
IcoRating2.gif 1KB
IcoRating4.gif 1KB
s5.jpg 2KB
IcoRating1.gif 1KB
s6.jpg 10KB
IcoRating0.gif 717B
index.php 2KB
ajax_search
ajax_search.js 10KB
jquery.js 30KB
ajax_search_all.gif 1KB
ajax_search.gif 1KB
ajax_search.php 7KB
ajax_search_dot.gif 35B
styles.css 1KB
共 21 条
- 1
资源评论
hnny_888
- 粉丝: 1
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 本地镜像源配置脚本本地镜像源配置脚本
- 与spoon配套使用的jdk
- 基于单片机的便携式粮食水分测试仪的研究
- 测绘基坑支护工程变形监测报告1.pdf
- 基于PHP+swoole实现的微信机器人,依赖vbot和微信网页版的功能,帮助管理微信群/聊天/踢人等+源码+开发文档+运行教程
- com.xunmeng.pinduoduo_Release_cd290ca9_ARM64.apk
- 2788727d-25a0-41b2-b6b4-265d193edb95.doc
- 基于AVR单片机的伺服电机系统研究
- Lab-Electronic Craft Practicum-2-Simulation of a Single Tube Com
- 贪吃蛇基于TypeScript
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功