天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP 分頁類(模仿google)-面試題目解答

筆試回答的不太好,特別是JS部分,也是許久都沒復習的原因。
上機題目是要寫一個仿google分頁的類,當要取類似9/2的最大整數,卻怎么也想不起函數ceil的名字,暈了半天。
最后測試程序沒錯誤,但是就是不能正常顯示,后來(回家后)一查才知道是語句:for($i=0;$i++;$i<9)寫錯了,于是下決心重新寫一遍,于是就有了下面的代碼了:
復制代碼 代碼如下:
<?php
/*
顯示樣式如下:
[1] 2 3 4 5 6 7 8 9 10 ...100 下頁 尾頁
首頁 上頁 1..12 13 14 15 [16] 17 18 19 20 ...100 下頁 尾頁
首頁 上頁 1..92 93 94 95 96 97 98 [99] 100

使用方法:
$currentPage = $_GET['page']?$_GET['page']:1;
$pagediv = new pagediv(500, 10, 11, $currentPage, 'test.php?page=');
$pagediv->show();

*/
class pagediv
{
public $part1;
public $part2;
public $part3;
public $part4;
public $part5;

/*
對下面的分頁顯示進行分割:
首頁 上頁 1..12 13 14 15 [16] 17 18 19 20 ...100 下頁 尾頁
$part1 : 首頁 上頁
$part2 : 1..
$part3 : 12 13 14 15 [16] 17 18 19 20
$part4 : ...100
$part5 : 下頁 尾頁
*/

public $allPage; //總頁數
public $allRocords; //總記錄數
public $perPage; //每頁記錄數
public $showPagesNo; //顯示分頁欄的總頁碼數 顯示樣式里共有11個
public $currentPage; //當前頁
public $urlModel; //Url鏈接樣式

public $startHidden; //出現 1... 時的頁數 開始隱藏中間頁
public $endHidden; //出現 ...100 時的頁數 結束隱藏中間頁

public function __construct($allRocords, $perPage, $showPagesNo, $currentPage, $urlModel){
$this->allRocords = $allRocords;
$this->perPage = $perPage;
$this->showPagesNo = $showPagesNo;
$this->currentPage = $currentPage;
$this->urlModel = $urlModel;
$this->allPage = $this->getAllPage();

$this->startHidden = $this->getInt(($this->showPagesNo)/2); //6
$this->endHidden = $this->allPage - $this->startHidden; //94
}

public function getUrl($_index = ''){
$_current = $_index;
if($_index == 'pre') $_current = $this->currentPage -1;
if($_index == 'next') $_current = $this->currentPage+1;
if($_index == '') $_current = $this->allPage;
return $this->urlModel.$_current;
}

public function getAllPage(){
return $this->getInt($this->allRocords/$this->perPage);
}

public function getInt($_float){
$_int = $_float;
if( $_index = strpos($_float,'.') == true ){
$_int = substr($_float,0,$_index);
$_int++;
}
//沒有想起ceil時的候補方案
return $_int;
}

public function getPart1(){
$content = '<a href="'.$this->getUrl(1).'">首頁</a> <a href="'.$this->getUrl('pre').'">上頁</a> ';
if($this->currentPage <= $this->startHidden){
$content = '';
}
return $content;
}

public function getPart2(){
$content = '<a href="'.$this->getUrl(1).'">1</a> ';
$add = '';
if($this->currentPage > $this->startHidden){
$add = '...';
}
if($this->currentPage == 1){
$content = '[1] ';
$add = '';
}
$part2 = $content.$add;
return $part2;
}

public function getPart3(){
$content = '';
if($this->currentPage <= $this->startHidden){
//[1] 2 3 4 5 6 7 8 9 10 ...100 下頁 尾頁
$long = $this->showPagesNo - 2;
for($i=0;$i<$long;$i++){
$j = $i+2;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] ';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a> ';
}

}

}elseif( $this->currentPage >= $this->endHidden ){
//首頁 上頁 1..92 93 94 95 96 97 98 [99] 100
$long = $this->showPagesNo - 2;
$_start = $this->allPage - $long;
for($i=0;$i<$long;$i++){
$j = $_start + $i;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] ';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a> ';
}
}
}else{
//首頁 上頁 1..12 13 14 15 [16] 17 18 19 20 ...100 下頁 尾頁
$long = $this->showPagesNo - 2;
$offset = $this->getInt($long/2) - 1;
$_start = $this->currentPage - $offset;
for($i=0;$i<$long;$i++){
$j = $_start + $i;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] ';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a> ';
}
}
}
$part3 = $content;
return $part3;
}

public function getPart4(){
$content = '<a href="'.$this->getUrl().'">'.$this->allPage.'</a> ';
$add = '';
if($this->currentPage < $this->endHidden){
$add = '...';
}
if($this->currentPage == $this->allPage){
$content = '['.$this->allPage.']';
$add = '';
}
$part4 = $add.$content;
return $part4;

}

public function getPart5(){
$content = '<a href="'.$this->getUrl('next').'">下頁</a> <a href="'.$this->getUrl().'">尾頁</a>';
if($this->currentPage >= $this->endHidden){
$content = '';
}
return $content;
}

public function show(){
//判斷非法
if(!is_numeric($this->currentPage) || $this->currentPage < 0 || $this->currentPage > $this->allPage){
print 'error:pageNo is flase';
return;
}
//總頁數沒有達到顯示分頁欄的總頁碼數,則全部顯示
if($this->allPage < $this->showPagesNo){
$long = $this->allPage;
for($i=0;$i<$long;$i++){
$j = $i+1;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] ';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a> ';
}

}
print $content;
return;
}
$this->part1 = $this->getPart1();
$this->part2 = $this->getPart2();
$this->part3 = $this->getPart3();
$this->part4 = $this->getPart4();
$this->part5 = $this->getPart5();

print $this->part1.$this->part2.$this->part3.$this->part4.$this->part5;
}
}
?>

php技術PHP 分頁類(模仿google)-面試題目解答,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 伦理片秋霞免费影院 | 人与畜禽CROPROATION免费 人淫阁 | 精品一二三区久久AAA片 | 我就去色色| 与邻居换娶妻子2在线观看 瑜伽牲交AV | 亚洲一二三产品区别在哪里 | 国产成人高清视频 | 国产毛片女人高潮叫声 | 亚洲日韩中文字幕区 | 久久夜色噜噜噜亚洲AV0000 | 亚洲免费无码中文在线 | 里番※琉璃全彩acg奈亚子 | 国产又色又爽又刺激在线播放 | 苍井空小公主qvod | 99在线这精品视频 | 中国午夜伦理片 | 全是肉的高h短篇列车 | a视频在线观看 | 最近中文字幕高清中文 | 无人区在线日本高清免费 | 久久一er精这里有精品 | 亚洲VA天堂VA欧美VA在线 | 久久久久99精品成人片三人毛片 | 99热久久精品国产一区二区 | 日韩精品亚洲专区在线电影不卡 | YELLOW视频在线观看最新 | 国产精品视频大全 | 一区视频免费观看 | 秋霞特色大片18岁入口 | 欧美老少欢杂交另类 | 国产精品视频yy9099 | 无码毛片内射白浆视频 | 2018高清国产一区二区三区 | 人禽l交视频在线播放 视频 | 国色天香视频在线社区 | 成年人视频在线免费看 | bbwvideos欧美老妇 | 大屁股妇女流出白浆 | 日本一卡二卡三卡四卡无卡免费播放 | 久久久精品免费视频 | 麻豆免费观看高清完整视频 |