search
Homephp教程PHP源码phpZF框架下类似Google搜索分页

phpZF框架下类似Google搜索分页

/**
	 *
	 * @param unknown_type $model 表类型
	 * @param unknown_type $ncontroller 那个控制器提交的controller
	 * @param unknown_type $naction 那个action提交的action
	 */
	public function fenyepage2($model,$ncontroller,$naction){
		if(!isset($_SESSION))
		{session_start();}
		$pageSize = $_SESSION['pagesize'];
		$pageNow = $_SESSION['pagenow'];
		$offset = ($pageNow-1)*$pageSize;
		$db = $this->getAdapter();
		$select = $db->select();
		$select->from('student','*');
		if(!isset($_SESSION))
		{session_start();}
		if($_SESSION['qsname']!=""){
			$sname = $_SESSION['qsname'];
			$select->where('sname like ?',"%$sname%");
		}
		if($_SESSION['qsaddress']!=""){
			$saddress = $_SESSION['qsaddress'];
			$select->where('saddress like ?',"%$saddress%");
		}
		if($_SESSION['qsdept']!=""){
			$sdept = $_SESSION['qsdept'];
			$select->where('sdept like ?',"%$sdept%");
		}
		$coutNews = $db->fetchAll($select);
		$pageCount = ceil(count($coutNews)/$pageSize);
		$select->limit($pageSize,$offset);//第一个参数:总共显示多少个。第二个参数:从第几个开始显示
		$res = $db->fetchAll($select);
		$native = null;
		$native = "首页&nbsp";
		if($pageNow>1){
			$nextPage = $pageNow-1;
			$native.=" 上一页 ";
		}
			if(($pageNow-1)>5){
				if($pageNow+4>$pageCount){//如果最后的页数和理应前面开始的页数小于10则
					$start = $pageCount-9;//开始的页数和结束的页数相差9
				}else{
					$start=$pageNow-5;//开始位置和结束位置相差5
				}
			}else{
				$start = floor(($pageNow-1)/10)*10+1;
			}
			if($pageCount>=$start+10){
				$index = $start+10;
			}
			else{
				$index = $pageCount+1;
			}

			for(;$start<$index;$start++){
				$native.="  $start";
			}
		if($pageNowarrs = $res;
		$model->native = $native;
	}

                   

 以上就是phpZF框架下类似Google搜索分页的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function