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. java设计模式(六) 命令模式

    [命令模式]将"请求"封装成对象,以便使用不同的请求,队列或者日志来参数化其他对象,命令模式也支持可撤销的操作. 1,定义命令接口 package com.pattern.comm ...

  2. 2016年第2周读书笔记与工作笔记 scrollIntoView()与datalist元素

    这一周主要是看了html5网页开发实例与javascript 高级程序设计,供以后翻阅查找.  html5网页开发实例第1章与第二章的2.1部分: 第1章内容: html5在w3c的发展史. 浏览器的 ...

  3. 网页提示[Not allowed to load local resource: file://XXXX]错误

    网页通过http 访问时, 点击打开文件的link.在Chrome 中会报 Not allowed to load local resource: file// XXXX 的错误 <!--Add ...

  4. MVC3缓存之一:使用页面缓存

    MVC3缓存之一:使用页面缓存 在MVC3中要如果要启用页面缓存,在页面对应的Action前面加上一个OutputCache属性即可. 我们建一个Demo来测试一下,在此Demo中,在View的Hom ...

  5. jquery $.each 和for怎么跳出循环终止本次循环

    1.for循环中我们使用continue:终止本次循环计入下一个循环,使用break终止整个循环. 2.而在jquery中 $.each则对应的使用return true 和return false. ...

  6. js截取文件的名称

    var str = 'aaa.fda.asp'; var arr = str.split('.');//通过\分隔字符串,成字符串数组 var last= arr[arr.length - 1];// ...

  7. oracle触发器调用java程序

    1.创建java程序:接收存储过程传递的参数,发送socket通信. create or replace and compilejava source named jym as import java ...

  8. bzoj3262: 陌上花开(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  9. UOJ34 多项式乘法

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  10. Android四大组件

    Activity 概念 活动是一种可以包含用户界面的组件,主要用于和用户交互.一个应用程序可以包含零个或多个活动. 基本用法 手动创建活动 1. 创建或加载布局 2. 在AndroidManifest ...