thinkphp搜索这里不填写关键词搜索,显示出所有列表出来
下面这个程序要怎么更改才能不填关键词不显示列表出来
<form action="/?m=search" method="post">
<input type="hidden" name="modelid" value="9" id="modelid2">
<input type="text" class="chunk" name="keyword" placeholder="请输入您要查询的条件" />
<button type="submit" class="" value="" target="menuFrame" />点击查询</button>
</form>
<?php
class SearchAction extends PublicAction
{
public function index()
{
$keyword = $_GET['keyword'] = I('keyword');
$modelid = $_GET['modelid'] = I('modelid', 9, 'intval');
$this->assign(I('request.'));
//可搜索内容模型
$model_search = array();
foreach ($this->Model as $val) {
if ($val['issearch'] == 1) {
$model_search[] = $val;
}
}
$this->assign('model_search', $model_search);
$this->assign('seo_title', $this->Config['seo_title']);
$this->assign('seo_keywords', $this->Config['seo_keywords']);
$this->assign('seo_description', $this->Config['seo_description']);
$modelname = $this->Model[$modelid]['tablename'];
$where = array();
$where['status'] = 1;
$where['lang'] = LANG_ID;
$where['title'] = array('like',"%$keyword%");
$db = M($modelname);
$count = $db->where($where)->count();
if($count) {
import("@.ORG.Page");
$page = new Page($count, 6);
$pages = $page->show();
$field = 'id,url,title,keywords,description,thumb,createtime,tel';
$list = $db->field($field)->where($where)->order('listorder desc,id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
$this->assign('pages', $pages);
$this->assign('list', $list);
}
fangke_log('search','index',0,$keyword);
$this->assign(I('get.'));
$this->display();
}
}
where 条件 里默认拼接一下 where 1=1 就好了。有输入关键字时根据关键字匹配输出,没有输入时全部输出。
只要把
$where['title'] = array('like',"%$keyword%");
$db = M($modelname);
$count = $db->where($where)->count();
改成
$count=0;
if($keyword!=''){
$where['title'] = array('like',"%$keyword%");
$db = M($modelname);
$count = $db->where($where)->count();
}
这样的话,你不输入关键词,就不会显示列表数据了