最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2009年09月13日 22:08:26   作者:  
今天去XX公司面試了,感覺(jué)很不理想。因?yàn)檫@一段時(shí)間都在加深Zend Framework,都沒(méi)練習(xí)常用函數(shù)和方法了。
筆試回答的不太好,特別是JS部分,也是許久都沒(méi)復(fù)習(xí)的原因。
上機(jī)題目是要寫(xiě)一個(gè)仿google分頁(yè)的類,當(dāng)要取類似9/2的最大整數(shù),卻怎么也想不起函數(shù)ceil的名字,暈了半天。
最后測(cè)試程序沒(méi)錯(cuò)誤,但是就是不能正常顯示,后來(lái)(回家后)一查才知道是語(yǔ)句:for($i=0;$i++;$i<9)寫(xiě)錯(cuò)了,于是下決心重新寫(xiě)一遍,于是就有了下面的代碼了:
復(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>&nbsp;<a href="'.$this->getUrl('pre').'">上頁(yè)</a>&nbsp;';
if($this->currentPage <= $this->startHidden){
$content = '';
}
return $content;
}

public function getPart2(){
$content = '<a href="'.$this->getUrl(1).'">1</a>&nbsp;';
$add = '';
if($this->currentPage > $this->startHidden){
$add = '...';
}
if($this->currentPage == 1){
$content = '[1]&nbsp;';
$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.']&nbsp;';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a>&nbsp;';
}

}

}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.']&nbsp;';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a>&nbsp;';
}
}
}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.']&nbsp;';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a>&nbsp;';
}
}
}
$part3 = $content;
return $part3;
}

public function getPart4(){
$content = '<a href="'.$this->getUrl().'">'.$this->allPage.'</a>&nbsp;';
$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>&nbsp;<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.']&nbsp;';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a>&nbsp;';
}

}
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;
}
}
?>

相關(guān)文章

  • 完美解決PHP中的Cannot modify header information 問(wèn)題

    完美解決PHP中的Cannot modify header information 問(wèn)題

    以下是對(duì)PHP中的Cannot modify header information問(wèn)題的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下
    2013-08-08
  • PHP中使用hidef擴(kuò)展代替define提高性能

    PHP中使用hidef擴(kuò)展代替define提高性能

    這篇文章主要介紹了PHP中使用hidef擴(kuò)展代替define提高性能,本文著重測(cè)試hidef的性能,同時(shí)介紹了安裝方法和使用示例,需要的朋友可以參考下
    2015-04-04
  • php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別

    php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別

    這篇文章主要介紹了php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別與介紹,需要的朋友可以參考下
    2017-04-04
  • PHP模版引擎原理、定義與用法實(shí)例

    PHP模版引擎原理、定義與用法實(shí)例

    這篇文章主要介紹了PHP模版引擎原理、定義與用法,結(jié)合實(shí)例形式分析了php模板引擎相關(guān)的模板編譯、緩存處理、變量替換等操作技巧,需要的朋友可以參考下
    2019-03-03
  • 在Mac上編譯安裝PHP7的開(kāi)發(fā)環(huán)境

    在Mac上編譯安裝PHP7的開(kāi)發(fā)環(huán)境

    這篇文章主要介紹了在Mac上編譯安裝PHP7的開(kāi)發(fā)環(huán)境的相關(guān)資料,需要的朋友可以參考下
    2015-07-07
  • 詳解php內(nèi)存管理機(jī)制與垃圾回收機(jī)制

    詳解php內(nèi)存管理機(jī)制與垃圾回收機(jī)制

    在PHP中,沒(méi)有任何變量指向這個(gè)對(duì)象時(shí),這個(gè)對(duì)象就成為垃圾。PHP會(huì)將其在內(nèi)存中銷毀;這是PHP的GC垃圾處理機(jī)制。PHP的內(nèi)存管理,分為倆部分, 第一部分是PHP自身的內(nèi)存管理,而第二部分是zend_alloc中描寫(xiě)的關(guān)于PHP自身的內(nèi)存管理。本文將詳細(xì)介紹這兩個(gè)內(nèi)容。
    2021-05-05
  • PHP使用PDO調(diào)用mssql存儲(chǔ)過(guò)程的方法示例

    PHP使用PDO調(diào)用mssql存儲(chǔ)過(guò)程的方法示例

    這篇文章主要介紹了PHP使用PDO調(diào)用mssql存儲(chǔ)過(guò)程的方法,結(jié)合簡(jiǎn)單實(shí)例形式分析了php基于pdo簡(jiǎn)單實(shí)現(xiàn)連接及調(diào)用存儲(chǔ)過(guò)程相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • php SQL防注入代碼集合

    php SQL防注入代碼集合

    php下實(shí)現(xiàn)sql防注入效果代碼,asp的比較多,php的倒不多見(jiàn),喜歡php的朋友可以參考下
    2008-04-04
  • PHP中使用協(xié)同程序?qū)崿F(xiàn)合作多任務(wù)

    PHP中使用協(xié)同程序?qū)崿F(xiàn)合作多任務(wù)

    這篇文章指導(dǎo)你通過(guò)使用協(xié)同程序來(lái)實(shí)施任務(wù)調(diào)度,通過(guò)實(shí)例實(shí)現(xiàn)對(duì)技術(shù)的理解。我將在前三節(jié)做一個(gè)簡(jiǎn)單的背景介紹。如果你已經(jīng)有了比較好的基礎(chǔ),可以直接跳到“協(xié)同多任務(wù)處理”一節(jié)
    2013-07-07
  • PHP實(shí)戰(zhàn)之投票系統(tǒng)的實(shí)現(xiàn)

    PHP實(shí)戰(zhàn)之投票系統(tǒng)的實(shí)現(xiàn)

    這篇文章主要為大家介紹了如何利用PHP制作一個(gè)投票系統(tǒng),文中的示例代碼講解詳細(xì),感興趣的小伙伴快跟隨小編一起學(xué)習(xí)一下
    2022-04-04

最新評(píng)論

吉安县| 望谟县| 双江| 客服| 孟村| 阿合奇县| 长丰县| 会昌县| 秀山| 深州市| 晋城| 元阳县| 郧西县| 乌海市| 昌都县| 江津市| 田东县| 双江| 西丰县| 泗水县| 大石桥市| 和林格尔县| 娱乐| 大埔县| 铜川市| 靖州| 义乌市| 青州市| 麟游县| 辽阳市| 汪清县| 微山县| 泾源县| 丘北县| 湛江市| 开封县| 西丰县| 开远市| 集贤县| 博野县| 江津市|