Perfect PHP article pagination class _php tutorial

Source: Internet
Author: User
Perfect PHP Tutorial Article pagination class
Class subpages{
Private $each _disnums;//The number of entries displayed per page
private $nums;//Total number of entries
Private $current _page;//the currently selected page
Private $sub _pages;//pages per display
private $pageNums;//Total pages
Private $page _array = Array ();//the array used to construct pagination
Private $subPage _link;//links for each page
Private $subPage _type;//shows the type of paging
/*
__construct is a subpages constructor that is used to run automatically when a class is created.
@ $each _disnums The number of entries displayed per page
@nums Total number of entries
@current_num the currently selected page
@sub_pages number of pages per display
@subPage_link links for each page
@subPage_type show the type of paging

When @subpage_type=1 is the normal paging mode
Example: A total of 4,523 records, each page shows 10, the current 1th/453 page [first] [prev] [next] [last page]
When @subpage_type=2 is a classic page-out style
Example: Current 1th 453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next] [last]
*/
function __construct ($each _disnums, $nums, $current _page, $sub _pages, $subPage _link, $subPage _type) {
$this->each_disnums=intval ($each _disnums);
$this->nums=intval ($nums);
if (! $current _page) {
$this->current_page=1;
}else{
$this->current_page=intval ($current _page);
}
$this->sub_pages=intval ($sub _pages);
$this->pagenums=ceil ($nums/$each _disnums);
$this->subpage_link= $subPage _link;
$this->show_subpages ($subPage _type); Call the Show_subpages function
echo $this->pagenums. " --". $this->sub_pages;
}
function __destruct () {
unset ($each _disnums);
Unset ($nums);
unset ($current _page);
unset ($sub _pages);
Unset ($pageNums);
unset ($page _array);
unset ($subPage _link);
unset ($subPage _type);
}
/*
The Show_subpages function is used inside the constructor. and used to determine what kind of paging to show.
*/
function show_subpages ($subPage _type) {
if ($subPage _type = = 1) {
$this->subpagecss1 ();
}elseif ($subPage _type = = 2) {
$this->subpagecss2 ();
}
}


/*
The function used to initialize the array that created the paging.
*/
function Initarray () {
for ($i =0; $i < $this->sub_pages; $i +) {
$this->page_array[$i]= $i;
}
return $this->page_array;
}
/*
Construct_num_page the function used to construct the displayed entry
Even if: [1][2][3][4][5][6][7][8][9][10]
*/
function Construct_num_page () {
if ($this->pagenums < $this->sub_pages) {
$current _array=array ();
for ($i =0; $i < $this->pagenums; $i +) {
$current _array[$i]= $i +1;
}
}else{
$current _array= $this->initarray ();
if ($this->current_page <= 3) {
for ($i =0; $i <>
$current _array[$i]= $i +1;
}
}elseif ($this->current_page <= $this->pagenums && $this->current_page > $this->pagenums-$ This->sub_pages + 1) {
for ($i =0; $i <>
$current _array[$i]= ($this->pagenums)-($this->sub_pages) +1+ $i;
}
}else{
for ($i =0; $i <>
$current _array[$i]= $this->current_page-2+ $i;
}
}
}
return $current _array;
}
/*
Constructing the paging of normal mode
Total 4,523 records, per page 10 article, current 1th/453 page [first] [prev] [Next] [end page]
*/
function SubPageCss1 () {
$subPageCss 1str= "";
$SUBPAGECSS 1str.= "Total". $this->nums. " Record, ";
$subPageCss 1str.= "per page". $this->each_disnums. " Article, ";
$subPageCss 1str.= "Current section". $this->current_page. " /". $this->pagenums." Page ";
if ($this->current_page > 1) {
$FIRSTPAGEURL = $this->subpage_link. " 1 ";
$PREWPAGEURL = $this->subpage_link. ($this->current_page-1);
$subPageCss 1str.= "[Home]";
$subPageCss 1str.= "[prev]";
}else {
$subPageCss 1str.= "[Home]";
$subPageCss 1str.= "[prev]";
}

if ($this->current_page < $this->pagenums) {
$LASTPAGEURL = $this->subpage_link. $this->pagenums;
$NEXTPAGEURL = $this->subpage_link. ($this->current_page+1);
$subPageCss 1str.= "[next page]";
$subPageCss 1str.= "[Last]";
}else {
$subPageCss 1str.= "[next page]";
$subPageCss 1str.= "[Last]";
}
echo $subPageCss 1Str;
}

/*
Constructing the pagination of Classic mode
Current 1th/453 [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next] [last]
*//* Product Page Use */
function SubPageCss2 () {
$subPageCss 2str= "";

Jason Edit
$subPageCss 2str.= "
  • Current section ". $this->current_page." /". $this->pagenums." Page
  • ";

    if ($this->current_page > 1) {
    $FIRSTPAGEURL = $this->subpage_link. " 1 ";
    $PREWPAGEURL = $this->subpage_link. ($this->current_page-1);
    $subPageCss 2str.= "
  • Home
  • ";
    $subPageCss 2str.= "
  • Previous page
  • ";
    }else {
    $subPageCss 2str.= "
  • Home
  • ";
    $subPageCss 2str.= "
  • Previous page
  • ";
    }

    $a = $this->construct_num_page ();
    for ($i =0; $i <>
    $s = $a [$i];
    if ($s = = $this->current_page) {
    $subPageCss 2str.= "
  • ". $s."
  • ";
    }else{
    $url = $this->subpage_link. $s;
    echo $url; exit;
    $subPageCss 2str.= "
  • ". $s."
  • ";
    echo $subPageCss 2Str;
    }
    }
    Exit
    if ($this->current_page < $this->pagenums) {
    $LASTPAGEURL = $this->subpage_link. $this->pagenums;
    $NEXTPAGEURL = $this->subpage_link. ($this->current_page+1);
    $subPageCss 2str.= "
  • Next page
  • ";
    $subPageCss 2str.= "
  • Last
  • ";
    }else {
    $subPageCss 2str.= "
  • Next page
  • ";
    $subPageCss 2str.= "
  • Last
  • ";
    }
    echo $subPageCss 2Str;
    }
    }


    http://www.bkjia.com/PHPjc/444974.html www.bkjia.com true http://www.bkjia.com/PHPjc/444974.html techarticle Perfect PHP Tutorial article page class subpages{private $each _disnums;//The number of entries per page private $nums;//Total number of entries private $current _page;//currently selected page Private $ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.