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;
}