PHP search criteria paging; import criteria into paging

Source: Internet
Author: User

Before the user thinkphp do paging encountered some paging problem; search conditions are brought into pagination:

$map [' article_title '] = UrlDecode ($_get[' article_title ']);
	$date _sosuo[' article_title ' = Array (' Like ', '% '. $map [' Article_title ']. %');
	$count  = $article->where ($date _sosuo)->count ();  Total number of bars
	$Page   = new page ($count, 10);//Instantiate page class incoming total record number and number of records per page 
	foreach ($map as $key => $val)
	{
		$ page->parameter.= "$key =". UrlEncode ($val). " & ";
	}
        $show   = $Page->show ();	 Paging display output
	$this->assign (' page ', $show);//Assignment paging output
         $list = $article->where ($date _sosuo)->order (" Article_sort ")->limit ($Page->firstrow. ', '. $Page->listrows)->select ();

To do so would be successful;

But I have trouble making some deliveries on the page; all myself wrote a PHP native paging condition;

 Public Function Index () {$client = M (' clients ');//Customer table//Search condition $where = ';
			if ($_get[' clients_state ']) {$page _w[' clients_state '] = UrlDecode ($_get[' clients_state ']); $where [' clients_state '] = array (' Like ', '% '. $page _w[' clients_state '). '
		%');
			} if ($_get[' Clients_name ']) {$page _w[' clients_name '] = UrlDecode ($_get[' clients_name ')); $where [' clients_name '] = array (' Like ', '% '. $page _w[' Clients_name '). '
		%');
			} if ($_get[' Clients_phone ']) {$page _w[' clients_phone '] = UrlDecode ($_get[' clients_phone ')); $where [' clients_phone '] = array (' Like ', '% '. $page _w[' Clients_phone '). '
		%');
		
		$where [' clients_qiandan_time '] = array (' lt ', ' 3600 ');
		$name _z = '; foreach ($page _w as $ke => $val) {$name _z. = $ke.
		= '. $val. ' & ';
		$count = $client->field (' Clients_id,clients_name,clients_phone ')->where ($where)->count ();  $Page _size = 10; Pagination number $page _count = ceil ($count/$Page _size);
		Total number of pages $init = 1;    $page _len = 5; Show number of pages $max _p = $paGe_count; Maximum number of pages $pages = $page _count; Total Pages//Judging current page number if (Empty ($_get[' page ')) | | 
		$_get[' page ']<0 {$page = 1; 
		}else {$page =$_get[' page ']; $page _len = ($page _len%2)? $page _len: $pagelen +1; Number of  //  $pageoffset = ($page _len-1)/2;  //number of page numbers $offset = $Page _size* ($p-1);  $result = $client->field (' Clients_id,clients_name,clients_
		Phone ')->limit ($offset, $Page _size)->where ($where)->select (); foreach ($result as $v) {echo $v [' Clients_name ']. '
		<br/> ';
		Echo ' <br/> ';
		$page _page = ';
		1, the total number of pages $pages, $Page _size per page, display pages $page _len $page _page. = "$page/$pages page"; if ($page!=1) {//The condition is brought into the paging $key. = "<a class= ' paging ' href=\ '". $_server[' Php_self ']. $name _z. " Page= ". ($page-1). " \ "> Prev </a>"; Previous page}else {$key. = "Previous page"; 
				Previous Page} if ($pages > $page _len) {//If the current page is less than or equal to the left offset if ($page <= $pageoffset) {$init = 1; 
			$max _p = $page _len; }else{//If the current page is greater than the left offset//If the current number right offset exceeds the maximumPagination if ($page + $pageoffset >= $pages + 1) {$init = $pages-$page _len+1; 
					Calculation $init of}else{//left and right offsets = $page-$pageoffset; 
				$max _p = $page + $pageoffset; 
			and/or Output page number for ($i = $init; $i <= $max _p $i + +) {if ($i = = $page) {$key. = ' <span> '. $i. ' </span> '; else {//The condition is brought into the paging $key. = "<a class= ' paging ' href=\" ". $_server[' Php_self ']. $name _z. " Page= ". $i." ">". $i. " 
			</a> "; } if ($page!= $pages) {//The condition is brought into the paging $key. = "<a class= ' paging ' href=\ '". $_server[' Php_self ']. $name _z. " Page= ". ($page + 1). " \ > Next </a>;//Next page}else {$key. = "Next page";//Next Page} echo $key; Output Paging}

Output effect

Use the native paging to feel the speed faster;

Personal opinion, do not spray ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.