首页 > php教程 > PHP源码 > PHP简单分页函数

PHP简单分页函数

PHP中文网
发布: 2016-05-25 17:12:16
原创
1056 人浏览过

PHP简单分页函数

 function getask(){
 	$sql = "select * from cms_ask where ansower <> &#39; &#39; ";
	//这里要改成方法
	$q_sq = mysql_query($sql);
	$count = mysql_num_rows($q_sq);
	$page_size = 8;
	$page_current = isset($GLOBALS[&#39;page&#39;]) ? intval($GLOBALS[&#39;page&#39;]) : 1;
	$page_count = ceil($count / $page_size);
	$page_start = $page_current - 4;
	$page_end = $page_current + 4;
	if ($page_current < 5) {
		$page_start = 1;
		$page_end = 5;
	}
	if ($page_current > $page_count - 4) {
		$page_start = $page_count - 8;
		$page_end = $page_count;
	}
	if ($page_start < 1)
		$page_start = 1;
	if ($page_end > $page_count)
		$page_end = $page_count;
	$pagebar = "";
	
	
	$sql = "select * from cms_ask  where ansower <> &#39; &#39; order by id desc limit " . (($page_current - 1) * $page_size) . "," . $page_size;

	$row=$this -> user -> getall("$sql");
 	foreach($row as $v){
 		echo &#39;问:&#39;.$v["question"].&#39;答:&#39;.$v["ansower"].date("Y-m-d H:i:s",$v["postTime"]).&#39;&#39;;
 		
  	}
 	
 	$pagebar .= "";

	
		$pagebar .= "";
		if ($page_current != 1) {
			 $pagebar .= &#39;FIRST&#39;;
			}
		for ($i = $page_start; $i <= $page_end; $i++) {
			if ($i == $page_current) {
				$pagebar .= "" . $i . "";
			} else {
				$pagebar .= "" . $i . "";
			}
		}

		
		if ($page_current != $page_count) {
			$pagebar .= "END";
		}

		$pagebar .= "";

		$pagebar .= "";
	
		echo $pagebar;
 }
登录后复制

                   

 以上就是PHP简单分页函数的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板