thinkphp3.2.3实现多条件查询实例.

时间:2022-09-24 14:36:46
                $data = M("datainfo");

			$projectsname = I('get.projectsname');//前台提交的模糊查询字段
			// 查询条件
			$where = "";
			empty($projectsname)?($where=""):($where="status=1 and projectsname like '%".$projectsname."%' or projectsname like '%".$projectsname."' or projectsname like '".$projectsname."%'");

		    $count = $data->where($where)->count(); // 查询满足要求的总记录数
		    $Page = new Page($count, 50); // 实例化分页类 传入总记录数和每页显示的记录数(50)

		    // 配置前台分页的显示页
		    $Page->setConfig('header', '共%TOTAL_ROW%条');
		    $Page->setConfig('first', '首页');
		    $Page->setConfig('last', '共%TOTAL_PAGE%页');
		    $Page->setConfig('prev', '上一页');
		    $Page->setConfig('next', '下一页');
		    $Page->setConfig('link', 'indexpagenumb'); //pagenumb 会替换成页码
		    $Page->setConfig('theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		    // 分页显示输出
		    $show = $Page->show(); 
		    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		    $list = $data->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
		    $this->assign('page', $show);
		    $this->assign("list", $list);