一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

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

筆試回答的不太好,特別是JS部分,也是許久都沒(méi)復(fù)習(xí)的原因。
上機(jī)題目是要寫一個(gè)仿google分頁(yè)的類,當(dāng)要取類似9/2的最大整數(shù),卻怎么也想不起函數(shù)ceil的名字,暈了半天。
最后測(cè)試程序沒(méi)錯(cuò)誤,但是就是不能正常顯示,后來(lái)(回家后)一查才知道是語(yǔ)句:for($i=0;$i++;$i<9)寫錯(cuò)了,于是下決心重新寫一遍,于是就有了下面的代碼了:
復(fù)制代碼 代碼如下:
<?php
/*
顯示樣式如下:
[1] 2 3 4 5 6 7 8 9 10 ...100 下頁(yè) 尾頁(yè)
首頁(yè) 上頁(yè) 1..12 13 14 15 [16] 17 18 19 20 ...100 下頁(yè) 尾頁(yè)
首頁(yè) 上頁(yè) 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;

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

public $allPage; //總頁(yè)數(shù)
public $allRocords; //總記錄數(shù)
public $perPage; //每頁(yè)記錄數(shù)
public $showPagesNo; //顯示分頁(yè)欄的總頁(yè)碼數(shù) 顯示樣式里共有11個(gè)
public $currentPage; //當(dāng)前頁(yè)
public $urlModel; //Url鏈接樣式

public $startHidden; //出現(xiàn) 1... 時(shí)的頁(yè)數(shù) 開(kāi)始隱藏中間頁(yè)
public $endHidden; //出現(xiàn) ...100 時(shí)的頁(yè)數(shù) 結(jié)束隱藏中間頁(yè)

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++;
}
//沒(méi)有想起ceil時(shí)的候補(bǔ)方案
return $_int;
}

public function getPart1(){
$content = '<a href="'.$this->getUrl(1).'">首頁(yè)</a> <a href="'.$this->getUrl('pre').'">上頁(yè)</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 下頁(yè) 尾頁(yè)
$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 ){
//首頁(yè) 上頁(yè) 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{
//首頁(yè) 上頁(yè) 1..12 13 14 15 [16] 17 18 19 20 ...100 下頁(yè) 尾頁(yè)
$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').'">下頁(yè)</a> <a href="'.$this->getUrl().'">尾頁(yè)</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;
}
//總頁(yè)數(shù)沒(méi)有達(dá)到顯示分頁(yè)欄的總頁(yè)碼數(shù),則全部顯示
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技術(shù)PHP 分頁(yè)類(模仿google)-面試題目解答,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久只有这才是精品99 | 天天躁日日躁狠狠躁中文字幕老牛 | 欧美激情成人网 | 国产中文字幕在线免费观看 | 97碰公开在线观看免费视频 | 激性欧美激情在线播放16页 | 色视频免费在线观看 | 久热精品视频在线观看99小说 | 国产一区二区中文字幕 | 日本在线观看一级高清片 | 午夜视频在线观看网站 | 九月色婷婷 | 国产91一区二区在线播放不卡 | 亚洲成人毛片 | 5月丁香婷婷 | 91视频原创| 亚洲另类图片专区 | 国产夜色 | 91久久精品国产免费一区 | 国产偷国产偷亚洲高清人乐享 | 亚洲欧美第一页 | 一区二区三区视频免费 | 国产女主播喷出白浆视频 | 88av影院| 色噜噜视频 | 亚洲视频二| 六月婷婷在线 | 九九综合九九综合 | 国产午夜视频在线观看网站 | 91社区视频在线观看 | 国产成人在线视频网站 | 91小仙女思妍高跟丝袜 | 精品视频一区二区三区在线播放 | 亚洲图片另类 | 色网站在线视频 | 99精品大香线蕉线伊人久久久 | 玖玖精品在线视频 | 日本网络视频www色高清免费 | 91妖精视频 | 久久香蕉精品 | 五月综合激情视频在线观看 |