Home >php教程 >php手册 >thinkphp implements paging fuzzy query

thinkphp implements paging fuzzy query

WBOY
WBOYOriginal
2016-08-20 08:48:181489browse

thinkphp implements fuzzy query and paging functions
$data = M("datainfo");

$projectsname = I('get.projectsname');//Fuzzy query field submitted by the front desk
// Query conditions
$where = "";
empty($projectsname)?($where=""):($where="status=1 and projectsname like '%".$projectsname."%' or projectsname like '%".$projectsname."' or projectsname like '".$projectsname."%'");

$count = $data->where($where)->count(); // Query the total number of records that meet the requirements
$Page = new Page($count, 50); // Instantiate the paging class and pass in the total number of records and the number of records displayed on each page (50)

// Configure the display page of the front page
$Page->setConfig('header', 'Total %TOTAL_ROW% items');
$Page->setConfig('first', 'Homepage');
$Page->setConfig('last', 'Total %TOTAL_PAGE% pages');
$Page->setConfig('prev', 'Previous page');
$Page->setConfig('next', 'next page');
$Page->setConfig('link', 'indexpagenumb'); //pagenumb will be replaced with page number
$Page->setConfig('theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
// Display output in pagination
$show = $Page->show();
// Perform paging data query. Note that the parameters of the limit method must use the attributes of the Page class
$list = $data->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select ();
$this->assign('page', $show);
$this->assign("list", $list);

thinkphp implements paging fuzzy query NodeController.class.zip (1.08 KB Download: 3 times)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn