thinkphp实现模糊匹配(学习贵哥代码)
模板文件:
控制器:
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 $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();
}
立即学习“PHP免费学习笔记(深入)”;
模型层:
public function listMember($firstRow = 0, $listRows = 20, $where) {
$M = M('Constant');
$list = $M->where($where)->limit("$firstRow , $listRows")->select();
return $list;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号