HTML代码

<form method="GET" action="index.php?">  //指向地址
  <input type="hidden" id="" name="m" value="Search"/>
  <select id="module" name="module" style="display:none"> //重点:获取模型
    <option selected="selected" value="Product">产品模型
    </option>
  </select>
<div class="input01">
  <input type="text" name="keyword" id="" class="input-text" value="" /> //关键词
</div><div class="button01">
<input type="image" src="/yt/Yourphp/Tpl/Home/new/Public/images/button01.jpg" />
</div>
</form>

php代码  \Yourphp\Lib\Action\Home\SearchAction.class.php

<?php
/**
*
* SearchAction.class.php (前台搜索功能)
*
* @package YOURPHP
* @author liuxun QQ:147613338 <admin@yourphp.cn>
* @copyright Copyright (c) 2008-2011 (http://www.yourphp.cn)
* @license http://www.yourphp.cn/license.txt
* @version YourPHP企业网站管理系统 v2.1 2011-03-01 yourphp.cn $
*/
if(!defined("Yourphp")) exit("Access Denied");
class SearchAction extends BaseAction
{ function _initialize()
{
parent::_initialize();
} public function index()
{
//搜索
$_REQUEST['id'] = $catid = intval($_REQUEST['id']);
$p= max(intval($_REQUEST[C('VAR_PAGE')]),);
$_REQUEST['keyword'] = $keyword = get_safe_replace($_REQUEST['keyword']);
$_REQUEST['module'] = $module = get_safe_replace($_REQUEST['module']);
$module = $module ? $module : 'Article' ;
$this->assign($_REQUEST);
$this->assign('bcid',);
$where = " status=1 "; if(APP_LANG){
$lang = LANG_NAME;
$langid= LANG_ID;
$where .=" and lang= $langid";
$this->assign('lang',$lang);
$this->assign('langid',$langid);
} if($catid){
$cat = $this->categorys[$catid];
$bcid = explode(",",$cat['arrparentid']);
$bcid = $bcid[];
if($bcid == '') $bcid=intval($catid);
if(empty($module))$module=$cat['module'];
unset($cat['id']);
$this->assign($cat);
$cat['id']=$catid;
$this->assign('catid',$catid);
$this->assign('bcid',$bcid); if($cat['child']){
$where .= " and catid in(".$cat['arrchildid'].")";
}else{
$where .= " and catid=".$catid;
}
}
$seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];
$this->assign ('seo_title',$keyword.' '.$seo_title);
$this->assign ('seo_keywords',$keyword.$cat['keywords']);
$this->assign ('seo_description',$keyword.$cat['description']); if($keyword){ if(strstr($keyword,'or')){
$keydo = ' or ';
$keyword_arr= explode('or',$keyword);
}elseif(strstr($keyword,' ')){
$keydo = ' AND ';
$keyword_arr= explode(' ',$keyword);
} if(count($keyword_arr)>){
foreach($keyword_arr as $key =>$keywordz){
$keyword_arr[$key] = ' title like "%'.trim($keywordz).'%" ';
}
$where .= ' AND ('.implode($keydo,$keyword_arr).')';
}else{
$where .= ' AND title like "%'.$keyword.'%" ';
}
}
$this->dao= M($module);
$count = $this->dao->where($where)->count();
$this->assign('count',$count); if($count){
import ( "@.ORG.Page" );
$listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
$page = new Page ( $count, $listRows );
$_REQUEST['p'] = '{$page}';
$page->urlrule = URL('Home-Search/index',$_REQUEST);
$pages = $page->show();
$field = $this->module[$cat['moduleid']]['listfields'];
$field = $field ? $field : 'id,catid,userid,url,username,title,title_style,keywords,description,thumb,createtime,hits';
$list = $this->dao->field($field)->where($where)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
$this->assign('pages',$pages);
$this->assign('list',$list);
} $this->display(); }
}
?>

yourphp搜索代码的更多相关文章

  1. 完善dedecms站内搜索代码,为搜索结果添加第*页

    自那些平凡而伟大的程序猿开发了内容管理系统(cms),为了让看客们更快地找到自己感兴趣的内容,他们不断完善站内搜索代码,形成了一个小型的站内搜索引擎.可能有些网站模板设计师没考虑到seo的问题,很多站 ...

  2. 一分钟加入google站内搜索代码

    一分钟加入google站内搜索代码| 一分钟加入google站内搜索代码|只有7行最精简.网上有很多 google 站内搜索代码,但是出于某些目的,很多都加入了多余的代码,从seo的角度来讲,是很不优 ...

  3. [转载]《Delphi 版 everything、光速搜索代码》 关于获取文件全路径 GetFullFileName 函数的优化

    Delphi 版 everything.光速搜索代码>,文章中关于获取文件全路径的函数:GetFullFileName,有一个地方值得优化. 就是有多个文件,它们可能属于同一个目录. 譬如 Sy ...

  4. Html 小插件5 百度搜索代码2

    网页添加百度搜索框代码大全 ★ 用法:在下面选择合适的样式,复制代码到网页中相应位置粘贴即可. ★ 样式一(200×30)代码: <iframe id="baiduframe" ...

  5. 自适应大邻域搜索代码系列之(1) - 使用ALNS代码框架求解TSP问题

    前言 上次出了邻域搜索的各种概念科普,尤其是LNS和ALNS的具体过程更是描述得一清二楚.不知道你萌都懂了吗?小编相信大家早就get到啦.不过有个别不愿意透露姓名的热心网友表示上次没有代码,遂不过瘾啊 ...

  6. python kd树 搜索 代码

    kd树就是一种对k维空间中的实例点进行存储以便对其进行快速检索的树形数据结构,可以运用在k近邻法中,实现快速k近邻搜索.构造kd树相当于不断地用垂直于坐标轴的超平面将k维空间切分,依次选择坐标轴对空间 ...

  7. [转载]Delphi 版 everything、光速搜索代码

    近日没啥事情,研究了一下 everything.光速搜索原理.花了一个礼拜时间,终于搞定. 废话不多说,直接上代码: unit uMFTSearchFile; { dbyoung@sina.com 2 ...

  8. stream,做减法,优化搜索代码。

    做一个搜索,三个输入条件,求这个条件的交集.起初我的思路是按照操作的流程,一步步的来做这三个筛选. let searchResults = []; //step1 根据id搜索,得到一个子集. if ...

  9. [php] 使用IDE的正则搜索代码

    ([^a-zA-Z_=$0-9/\[\>])('|"|,)?(\s*)store_banner(\s*)('|"|,)?([^a-zA-Z_=$0-9\/\(\]:]) 用在 ...

随机推荐

  1. 【BZOJ 1857】【SCOI 2010】传送带

    三分套三分,虽然简单,但是也得掌握,,, 时间复杂度$O(log_{1.5}^2 n)$ 一开始WA好几次发现是快速读入里没有return,这样也能过样例?_(:3J∠)_ #include<c ...

  2. ES6 变量的解构赋值

    数组的解构赋值     var [a,b,c] = [1,2,3];    左边是变量,右边是值,根据数据结构一一对应 只要等号两边的模式相同,左边的变量就会被赋予右边对应的值,必须模式相同 如果等号 ...

  3. python日常-list and dict

    什么是list: list 觉得算是python日常编程中用的最多的python自带的数据结构了.但是python重的list跟其他语言中的并不相同. 少年..不知道你听说过python中的appen ...

  4. C# 常用加密方式

    using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;u ...

  5. C++强制类型转换操作符 dynamic_cast

    dynamic_cast是四个强制类型转换操作符中最特殊的一个,它支持运行时识别指针或引用. >>>>>>>>>>>编译器的RTTI设 ...

  6. python3下的paramiko 安装

    环境为centos6.7 python3为源码编译安装的,系统自带的python2 可以直接使用paramiko模块,但是在py3的环境下加载出错,所有需要安装新的paramiko 模块: 上了par ...

  7. 【VS2013】设定Nuget代理

    @tags "visual studio 2013" nuget vs2013中用nuget想必是一件很爽的事情,就像java里面用maven来安装各种包一样.有时候网络不好,nu ...

  8. 【BZOJ-3122】随机数生成器 BSGS

    3122: [Sdoi2013]随机数生成器 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1362  Solved: 531[Submit][Sta ...

  9. SQL Server在更改计算机名后的设置

    把原来的账号删除 再添加现有的账号 添加权限 搞定了上面的账号配置,接下来就是设置服务器名称 参考:http://www.cnblogs.com/EasonJim/p/6114249.html 后话: ...

  10. 订阅Linux内核的邮件列表

    1.发送订阅邮件 注意:一定不要使用像Foxmail这样的第三方邮件客户端,因为发送的邮件会转码,导致订阅不成功,推荐使用Gmail,直接登录进去发送. 发送邮件内容: 接收人:majordomo@v ...