BVB Source Codes

Program V1.0 AjaxQuickSearch fast display search results Show ajax_search.php Source code

Return Download Program V1.0 AjaxQuickSearch fast display search results: download ajax_search.php Source code - Download Program V1.0 AjaxQuickSearch fast display search results Source code - Type:.php
  1. <?php
  2.  
  3. //*   Ajax快速搜索结果程序 - Ajax Quick Search Results  
  4. //*   Copyright  2008 - 2010 闻泰网络
  5. //*   http://www.weentech.com              
  6.  
  7.  
  8. $minimum_length = 3; // 在搜索输入框中键入多少个字符后,开始进行Ajax查询. 要求和ajax_search.js文件中的设置的值保持一致
  9. $result_limits = 6;      // 当搜索结果数量大于此数目时,快速结果显示框底部显示“更多搜索结果”的图片和链接
  10. $search_mode = 'OR';      // 设置为 'OR' 表示只要匹配一个关键词,设置为 'AND' 表示要匹配所有关键词
  11. $rootpath = './../';           // 网站的根目录
  12.  
  13. if (isset($_GET['ween_search_query']) && strlen($_GET['ween_search_query']) >= 3) {
  14.         $search_keywords = sqlsafefilter($_REQUEST['ween_search_query']);
  15. }else{
  16.         exit();
  17. }
  18.  
  19. //以下是两个函数
  20. function EscapeEntity($string)
  21. {
  22.         return str_replace(array('&', '"', '<', '>'), array( '&amp;','&quot;', '&lt;', '&gt;'), $string);
  23. }
  24.  
  25.  
  26. // sqlsafefilter()函数过滤非法的MYSQL查询,这里比较严格,可根据自己的需要删减过滤的字符
  27. function sqlsafefilter( $source )
  28. {
  29.         $entities_match         = array(',',';','$','!','@','#','%','^','&','*','_','(',')','+','{','}','|',':','"','<','>','?','[',']','\\',"'",'.','/','*','+','~','`','=');
  30.         $entities_replace   = array(' ',' ','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
  31.         return str_replace($entities_match, $entities_replace, trim($source));
  32. }
  33.  
  34.  
  35. // 以下搜索代码是示例,需要根据自己的网站系统所使用的数据库查询函数等定制
  36. if(file_exists($rootpath . 'includes/core.php')){
  37.  
  38.         define('IN_WEENCOMPANY', true);
  39.  
  40.         if(isset($_GET['lang']) AND (!isset($_COOKIE['weenCompany_forelang']) OR $_COOKIE['weenCompany_forelang'] != $_GET['lang']))
  41.         {
  42.                 $lang = strtolower($_GET['lang']);
  43.                 if($lang == 'cn' OR $lang == 'en'){
  44.                         setcookie("weenCompany_forelang", $lang, 0, "/");
  45.                         Header("Location: $_SERVER[REQUEST_URI]");
  46.                         exit();
  47.                 }
  48.         }  
  49.  
  50.         include($rootpath . 'includes/core.php');
  51.  
  52.         if($sitedefaultlang == 'en')
  53.         {
  54.                 $forelang='en';
  55.         }else{
  56.                 $forelang='cn';
  57.         }
  58.  
  59.         $keywords = explode (' ', $search_keywords);
  60.         if(strtoupper($search_mode) == 'OR'){
  61.           $boolean_type = 'OR';
  62.         }else{
  63.           $boolean_type = 'AND';
  64.         }
  65.         $query_where .= '(';
  66.         foreach ($keywords as $key => $value)
  67.         {
  68.                 $query_where .= " (title LIKE '%".$value."%' OR description LIKE '%".$value."%' OR specification LIKE '%".$value."%' OR priceship LIKE '%".$value."%') " . $boolean_type;
  69.         }
  70.  
  71.         unset ($keywords);
  72.         $query_where = rtrim ($query_where, ' ' . $boolean_type);
  73.         $query_where .= ')';
  74.  
  75.         $get_datas = $DB->query("SELECT imageid, title, images, price, rating FROM " . TABLE_PREFIX . "m17_products
  76.                                                          WHERE activated = '1' AND ".$query_where."
  77.                                                          ORDER BY datecreated DESC
  78.                                                          LIMIT " . ($result_limits + 1) . "");     //($result_limits + 1)表示只搜索比限制的多一个就可以了,搜索多了也不显示
  79.  
  80.  
  81.         $search_counts = $DB->get_num_rows($get_datas);
  82.  
  83.         if ($search_counts <1) {
  84.                 exit();
  85.         }
  86.  
  87.         $view_all = '';
  88.         if ($search_counts > $result_limits) {
  89.                 $view_all = sprintf(' view_all="%s"', EscapeEntity(sprintf('<a href="%ssearch.php?ween_search_query=%s">%s</a>', $rootpath, $search_keywords, '.')));
  90.         }
  91.  
  92.         echo '<?xml version="1.0"?>'."\n";
  93.         echo sprintf('<results type="%s" result_count="%s"%s>'."\n", '快速搜索结果:', $search_counts, $view_all);
  94.  
  95.         while($data = $DB->fetch_array($get_datas))
  96.         {
  97.                 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']))));
  98.         }
  99.         echo "</results>\n";
  100.  
  101.         exit();
  102.  
  103. }
  104. // 以上搜索代码需要根据自己的网站系统所使用的数据库查询函数等定制
  105.  
  106.  
  107.  
  108. // 以下代码是显示测试数据,无实际用途,当使用上面的实际搜索代码时,以下代码需要删除
  109. $view_all = '';
  110. $search_counts  = 7;
  111. if ($search_counts > $result_limits) {
  112.         $view_all = sprintf(' view_all="%s"', EscapeEntity(sprintf('<a href="%ssearch.php?ween_search_query=%s">%s</a>', $rootpath, $search_keywords, '.')));
  113. }
  114.  
  115. echo '<?xml version="1.0"?>'."\n";
  116. echo sprintf('<results type="%s" result_count="%s"%s>'."\n", '快速搜索结果:', 118, $view_all);
  117. 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)));
  118. 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)));
  119. 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)));
  120. 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)));
  121. 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)));
  122. 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)));
  123. 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)));
  124. echo "</results>\n";
  125. // 以上代码是显示测试数据,无实际用途,当使用上面的实际搜索代码时,以上代码需要删除
  126.  
  127.  
  128.  
  129. ?>
  130.  
  131.  
downloadajax_search.php Source code - Download Program V1.0 AjaxQuickSearch fast display search results Source code
Related Source Codes/Software:
Baidu know PHP pseudo static pseudo original real-time updating the thief v2.0 - Version 2.0 upgrade instructions   For bette... 2016-10-18
Drupal v7.9 multilingual version - Drupal7 version is finally released! Have been lon... 2016-10-18
Sina tencent FEED release v1.0 authorized everyone connected with a key - Sina weibo and tencent weibo, renren authorized co... 2016-10-18
Bulletin board system KaiBB v2.0.1 - KaiBB is a free open source bulletin board system,... 2016-10-18
XQCMS enterprise website system V4.0 beta mysql version - This CMS is designed for people to use, not a prog... 2016-10-18
Canphp framework v1.5 (PHP framework) - CanPHP framework (CP for short) is a simple, free,... 2016-10-18
8 boy simple m table v2.0 - Multi-purpose domain meters super easy procedure, ... 2016-10-18
Optimal source v2.02 moxa english-chinese translation translation - The background of new online editing template the ... 2016-10-18
Beautify the edition/PHP order submission system with the function of E-mail and SMS alerts - Program description: Currently most downloadable A... 2016-10-18
Link grid edition v2.0 beautification - Function description: 2016-10-18
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top