这个php网站搜索程序怎麼改,才能实现模糊搜索?
<?phpclassSearchControllerextendsBaseController{publicfunctioninit(){$this->class=Com...
<?php
class SearchController extends BaseController
{
public function init()
{
$this->class = Comment::readCache('category_2');
App::loadClass('Cookie',false);
}
public function index()
{
//安全过滤关键字
$keyword = safe_replace(trim($this->request->get('key')));
$keyword = safe_html($keyword);
$big = safe_int($this->request->post('big'));
//$small = safe_int($this->request->get('small'));
$cid = $big;
if (empty($keyword)){
$this->error($this->lang->get("search_msg"));
}
//搜索间隔时间判断
$last_time = Cookie::get('last_time');
$time = App::getConfig('search_time');
if (!empty($last_time) && !$this->request->isQuery('page'))
{
if (GET_TIME - $last_time < $time)
{
$this->error(sprintf($this->lang->get("search_time"),$time));
}
}
$data = App::model('Module')->find(2);
$product = App::model('Product');
$where = array();
if (!empty($keyword)){
$where[] = "product_name like '%$keyword%' or enproduct_name like '%$keyword%'";
}
if (!empty($cid)){
$rows = $this->cate[$cid];
if ($rows['child'])
$where[] = "cid in ($cid,{$rows['arrchildid']})";
else
$where[] = "cid = $cid";
}
$counts = $product->Count($where);
$field = $data['show_field'];
$counts = $product->Count($where);
$page = $this->getPage($counts,20);
$result = $product->findAll($where,'*','id desc',$page['limit']);
$aMenu = $this->class;
$aM = array();
foreach( $aMenu as $val ){
$aM[$val['cid']] = $val;
if(!empty($val['child_list'])){
foreach( $val['child_list'] as $v ){
$aM[$v['cid']] = $v;
if(!empty($v['child_list'])){
foreach($v['child_list'] as $v1){
$aM[$v1['cid']] = $v1;
} 展开
class SearchController extends BaseController
{
public function init()
{
$this->class = Comment::readCache('category_2');
App::loadClass('Cookie',false);
}
public function index()
{
//安全过滤关键字
$keyword = safe_replace(trim($this->request->get('key')));
$keyword = safe_html($keyword);
$big = safe_int($this->request->post('big'));
//$small = safe_int($this->request->get('small'));
$cid = $big;
if (empty($keyword)){
$this->error($this->lang->get("search_msg"));
}
//搜索间隔时间判断
$last_time = Cookie::get('last_time');
$time = App::getConfig('search_time');
if (!empty($last_time) && !$this->request->isQuery('page'))
{
if (GET_TIME - $last_time < $time)
{
$this->error(sprintf($this->lang->get("search_time"),$time));
}
}
$data = App::model('Module')->find(2);
$product = App::model('Product');
$where = array();
if (!empty($keyword)){
$where[] = "product_name like '%$keyword%' or enproduct_name like '%$keyword%'";
}
if (!empty($cid)){
$rows = $this->cate[$cid];
if ($rows['child'])
$where[] = "cid in ($cid,{$rows['arrchildid']})";
else
$where[] = "cid = $cid";
}
$counts = $product->Count($where);
$field = $data['show_field'];
$counts = $product->Count($where);
$page = $this->getPage($counts,20);
$result = $product->findAll($where,'*','id desc',$page['limit']);
$aMenu = $this->class;
$aM = array();
foreach( $aMenu as $val ){
$aM[$val['cid']] = $val;
if(!empty($val['child_list'])){
foreach( $val['child_list'] as $v ){
$aM[$v['cid']] = $v;
if(!empty($v['child_list'])){
foreach($v['child_list'] as $v1){
$aM[$v1['cid']] = $v1;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询