当前位置:Gxlcms > PHP教程 > thinkphp实现模模糊糊匹配(学习贵哥代码)

thinkphp实现模模糊糊匹配(学习贵哥代码)

时间:2021-07-01 10:21:17 帮助过:7人阅读

thinkphp实现模糊匹配(学习贵哥代码)

模板文件:





资讯管理-{$site.SITE_INFO.name}

$addCss="";
$addJs="";
$currentNav ='资讯管理 > 资讯列表';












资讯列表


















控制器:

public function index() {
//作为搜索条件查找某律师的信息
$where = '1=1';
if(!empty($_GET['name'])) $where .= ' and true_name regexp \'' . trim($_GET['name']) . '\'';
if(!empty($_GET['mobile'])) $where .= ' and law_mobile regexp \'' . trim($_GET['mobile']) . '\'';
if(!empty($_GET['email'])) $where .= ' and email regexp \'' . trim($_GET['email']) . '\'';
if(!empty($_GET['sex'])) $where .= ' and sex regexp \'' . trim($_GET['sex']) . '\'';
if(!empty($_GET['st'])) $where .= ' and first_date >= \'' . substr(str_replace('+', ' ', $_GET['st']),0,4) . '\'';
if(!empty($_GET['et'])) $where .= ' and first_date <= \'' . substr(str_replace('+', ' ', $_GET['et']),0,4) . '\'';
$M = M("Constant");
$count = $M->where($where)->count();
import("ORG.Util.Page"); // 导入分页类
$d = new Page($count,15); //分页
$list=$M->limit($d->firstRow.','.$d->listRows)->select();
$dd=$d->show();
$this->assign('list', D('Lawerinfo')->listMember($d->firstRow, $d->listRows, $where));
$this->assign('page',$dd);
$this->display();
}


模型层:

public function listMember($firstRow = 0, $listRows = 20, $where) {
$M = M('Constant');

$list = $M->where($where)->limit("$firstRow , $listRows")->select();

return $list;
}


人气教程排行