PHP 페이징 클래스(소스 코드 예)
分享一个php分页类,写的不错,提供了二个该分页类的调用实例,供大家学习参考。
1,php分页类代码 <?php /** * php分页类 * by bbs.it-home.org */ //定义错误级别 error_reporting(E_ALL); //分页类 class pagination{ public $Start; // 开始mysql查询 public $End; // 结束mysql查询 private $Number; //分布数据的数量 public $Pages; // 页数 private $N_p_p; //每页要显示的内容数量 private $Page_number; //当前页数 private $Buttons; //最大显示的按钮数,即每页面中显示出的页数 function __construct($number,$n_p_p=10,$page_number=1,$buttons=5) { //page start from 1 $page_number = ($page_number<1) ? 1 : $page_number ; $this-> Number = $number; $this-> N_p_p = $n_p_p; $this-> Pages = ceil ( $this-> Number / $this-> N_p_p ) ; $this-> Buttons = $buttons ; $page_number= ($page_number>$this->Pages) ? $this->Pages : $page_number ; $this-> Page_number = $page_number ; $this-> Ret() ; } public function Show_Pagination($link,$get='page',$div_class_name='pagination') { //if pages == 1 , no need to print pagination if($this->Pages==1)return; //$link is the addres of current page //$get is name of get method //echo pagination's div echo'<div class="'.$div_class_name.'">'; //echo pre button if($this->Page_number>1)echo 'Page_number -1 ).'">Per '; else echo 'Per '; //print button $this->Buttons=(int)$this->Buttons; $start_counter = $this->Page_number-floor($this->Buttons/2);//for normal mode $end_conter = $this->Page_number+floor($this->Buttons/2);//for normal mode //try to buttons exactly equal to $Buttons if($start_counter<1) $end_conter=$end_conter+abs($start_counter); if($end_conter>$this->Pages) $start_counter=$start_counter-($end_conter-$this->Pages); if(($this->Page_number-floor($this->Buttons/2))<1)$end_conter ++; for ($i=$start_counter;$i<=$end_conter;$i++) { if($i>$this->Pages || $i<1)continue; //no print less than 1 value or grater than totall page if($i==$this->Page_number)echo ' '.$i.' '; // change current page' class else echo ' '.$i.' '; // normal pages } //echo next button if($this->Page_number<$this->Pages)echo 'Page_number +1 ) .'">Nex '; else echo 'Nex '; //close div tag echo'</div>'; } //give the page number and return start and end of selection private function Ret() { $this->Start=(($this->Page_number-1)*$this->N_p_p); $this->End= $this->N_p_p ; } } 로그인 후 복사 2,分页类的示例一 <html> <head> <style type="text/css"> /* style for show*/ .pagination{direction:ltr} .pagination a{border-radius:3px;background-color:#eee;color:#555;border:1px solid #aaaaaa;padding-top:2px;padding-bottom:2px; padding-right:5px;padding-left:5px;text-decoration:none;} .pagination a:hover ,.pagination .cur{border-color:#0C52CE;color:#0C52CE;background-color:#fff;} </style> <title>php分页类示例---bbs.it-home.org</title> </head> <?php //include class: require_once"pagination.php"; //get the numbet of current page //note! you should safe it if(isset($_GET['page'])){ $page=$_GET['page']; } else $page=1; //connect to db ... mysql_connect("localhost","root","");//use your host,username and password to connect to the db mysql_select_db("dbname");//select your database //run query to get number of all records $query=mysql_query("select count(id) from table"); //raplace table with your table name $totall=mysql_result($query,0); //creat new object $pagination=new pagination($totall,3 /*number of content per page*/,$page,5 /*number of button to show*/); //get records of current page $SecondQuery=mysql_query("select id from table order by id desc limit $pagination->Start , $pagination->End"); //echo your result while($row=mysql_fetch_assoc($SecondQuery)) { echo 'id='.$row['id'].'<br>'; } //show pagination: $pagination->Show_Pagination("ExampleMysql.php?param1=value1",'page','pagination'); ?> 로그인 후 복사 3,分页类的调用示例二 <html> <head> <style type="text/css"> /* style for show*/ .pagination{direction:ltr} .pagination a{border-radius:3px;background-color:#eee;color:#555;border:1px solid #aaaaaa;padding-top:2px;padding-bottom:2px; |padding-right:5px;padding-left:5px;text-decoration:none;} .pagination a:hover ,.pagination .cur{border-color:#0C52CE;color:#0C52CE;background-color:#fff;} </style> <title>php分页类的调用示例-bbs.it-home.org</title> </head> <?php //include分页类文件 require_once "pagination.php"; //param of url to specify page_number $get_param='page'; //get current page from url $current_page=(isset($_GET[$get_param]) && is_numeric($_GET[$get_param]))?$_GET[$get_param]:1; //notice: when get param , youe should SAFE it //get totall available content // for example you can get number of news from news table in database ( mysql_num_rows or count()) $totall_content=120; // for example //creat new cat object $cat=new pagination($totall_content,10 /*number of content per page*/,$current_page,5 /*number of button*/); //when you want to load content of page: for example in db queris : // select * from table where conditions order by key limit $cat->Start , $cat->End //for show : $cat->Show_Pagination("example.php?",'page','pagination'); ?> </html> 로그인 후 복사 |

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Alipay PHP ...

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

기사는 입력 유효성 검사, 인증 및 정기 업데이트를 포함한 취약점을 방지하기 위해 프레임 워크의 필수 보안 기능을 논의합니다.

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...
