码迷,mamicode.com
首页 > Web开发 > 详细

yourphp搜索代码

时间:2014-05-29 11:57:24      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

HTML代码

bubuko.com,布布扣
<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>
bubuko.com,布布扣

 

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

bubuko.com,布布扣
<?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)]),1);
        $_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,0);
        $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[1]; 
            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)>1){
                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();

    } 
}
?>
bubuko.com,布布扣

 

yourphp搜索代码,布布扣,bubuko.com

yourphp搜索代码

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/wesky/p/3756596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!