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

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

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

筆記試験、特に JS の部分にあまりうまく答えられなかったので、長い間見直していませんでした。
コンピュータの質問は、Googleのページングを模倣するクラスを書くというもので、9/2のような最大の整数を取得したいとき、関数ceilの名前が思い出せず、長い間めまいを感じていました。
結局、テストプログラムではエラーは出なかったのですが、後で(帰宅後)確認してみると、for($i=0;$という文があったことが分かりました。 i;$i

コードをコピーコードは次のとおりです:


/*
表示形式は次のとおりです:
[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 = 'ホームページ 前のページ ';
if($this-> ;currentPage startHidden){
$content = '';
return $content;

public function getPart2(){
$content = '1
$add = ''; this->currentPage > $this->startHidden){
$add = '...' ;
}
if($this->currentPage == 1){
$content = '[1] ';
$add = '';
$part2 = $content.$add
$part2; >パブリック関数 getPart3(){
$content = '';
if($this-> currentPage startHidden){
//[1] 2 3 4 5 6 7 8 9 10 ...100 次のページ 最後のページ
$long = $this->showPagesNo - 2;
for($i=0;$i$j = $i 2;
if($j == $this->currentPage){
$content .= '['.$this->currentPage.'] '; }else{
$content .= ''.$j.' }

}

}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$j = $_start $i;
if($j = = $this->currentPage){
$content .= '['.$this- >currentPage.'] ';
}else{
$content .= ''.$j. ';
}
}
}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 .= ''.$j.' ';
}
}
}
$part3 = $content;
return $part3;
}

public function getPart4(){
$content = ''.$this->allPage.'  ';
$add = '';
if($this->currentPage endHidden){
$add = '...';
}
if($this->currentPage == $this->allPage){
$content = '['.$this->allPage.']';
$add = '';
}
$part4 = $add.$content;
$part4 を返す;

}

public function getPart5(){
$content = '下页 尾页';
if($this->currentPage >= $this->endHidden){
$content = '';
}
$content を返します。
}

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

}
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 までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。