ホームページ php教程 php手册 PHP ページング クラス (Google を模倣) - 面接の質問への回答

PHP ページング クラス (Google を模倣) - 面接の質問への回答

Jun 13, 2016 pm 12:22 PM
google php ページネーション 答え レビュー 良い 真似する 筆記試験 親切 答え 一部 インタビュー

筆記試験、特に 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();

*/
クラス pagediv
{
public $part1; ;
public $part3;
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; //ページングバーの合計ページ数を表示します。
public $currentPage; //現在のページ
public $urlModel; //1... が中間を隠し始めるときのページ数page
public $endHidden; //...100 が表示された場合 ページ数が終了し、中間ページが非表示になります

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

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

パブリック関数 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; $content = '<a href="'.$this->getUrl(1)。 '">ホームページ</a> <a href="'.$this->getUrl('pre' ).'">前のページ</a> ';
if($this-&gt ;currentPage <= $this->startHidden){
$content = '';
return $content;

public function getPart2(){
$content = '<a href="'.$this->getUrl(1).'" >1</a>
$add = ''; this->currentPage > $this->startHidden){
$add = '...' ;
}
if($this->currentPage == 1){
$content = '[1] ';
$add = '';
$part2 = $content.$add
$part2; >パブリック関数 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 -
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 $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;
$part4 を返す;

}

public function getPart5(){
$content = '<a href="'.$this->getUrl('next').'">下页</a> <a href="'.$this->getUrl().'">尾页</a>';
if($this->currentPage >= $this->endHidden){
$content = '';
}
$content を返します。
}

public function show(){
//非判断法
if(!is_numeric($this->currentPage) || $this->currentPage < 0 | | $this->currentPage > $this->allPage){
print 'error:pageNo は flase';
戻る;
}
//表示分数の总页コード数はありません、すべて表示
if($this->allPage < $this->showPagesNo){
$長い = $this->allPage;
for($i=0;$i$j = $i 1;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] ';
}else{
$content .= '<a href="'.$this->getUrl($j).'">'.$j.'</a> ';
}

}
print $content;
戻る;
}
$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;
}
}
?>

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットな記事タグ

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

CakePHP の日付と時刻

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

CakePHP プロジェクトの構成

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

CakePHP ファイルのアップロード

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

CakePHP ルーティング

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP について話し合う

Google、AI Test Kitchen & Imagen 3 をほとんどのユーザーに公開 Google、AI Test Kitchen & Imagen 3 をほとんどのユーザーに公開 Sep 12, 2024 pm 12:17 PM

Google、AI Test Kitchen & Imagen 3 をほとんどのユーザーに公開

CakePHP クイックガイド CakePHP クイックガイド Sep 10, 2024 pm 05:27 PM

CakePHP クイックガイド

See all articles