Simple php paging code-Support for smarty template paging-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Php & nbsp; classMy_Lib_page {& nbsp; current page & nbsp; & nbsp; var $ page1; & nbsp; & nbsp script ec (2); script

Class My_Lib_page {
// Current page
Var $ page = 1;
// Number of entries per page
Var $ size = 20;
// Total number of records
Var $ count;
// Number of entries per column
Var $ lun = 10;
// Parameter binding
Var $ param;
// Jump
Var $ run;
// Name = admin & pwd = 2132 & sex = 1
// $ _ GET ['name'] = admin;
Private function setParam (){
$ Param = $ this-> param;
Unset ($ param ['page']);
If (is_array ($ param )&&! Empty ($ param )){
Foreach ($ param as $ key => $ value ){
$ Data [] = $ key. "/". $ value;
}
$ This-> url = implode ("/", $ data );
$ This-> param = $ this-> url;
$ This-> url = "/". $ this-> url;
} Else {
If (! Empty ($ param )){
$ This-> url = $ param;
$ This-> param = $ this-> url;
$ This-> url = "/". $ this-> url;
}
}
}

Function pageDate (){
$ This-> setParam ();
$ Num = ceil ($ this-> lun/2 );
$ This-> page = intval ($ this-> page );
$ This-> page = $ this-> page <= 0? 1: $ this-> page;

$ Cpage ['countpage'] = ceil ($ this-> count/$ this-> size); // total number of pages

$ Cpage ['page'] = $ this-> page> $ cpage ['countpage']? $ Cpage ['countpage']: $ this-> page;
// Current page

// Display the total number
$ Cpage ['lun '] = $ cpage ['countpage'] <$ this-> lun? $ Cpage ['countpage']: $ this-> lun;

// Start page number
$ Cpage ['start'] =$ this-> page> $ num-1? $ This-> page-$ num + 1: 1;

$ Cpage ['start'] = ($ cpage ['start'] + $ cpage ['lun ']) >=$ cpage ['countpage']? $ Cpage ['countpage']-$ cpage ['lun '] + 1: $ cpage ['start'];

// Display parameters
$ Cpage ['url'] = $ this-> url;

// Control redirection
$ Cpage ['run'] = $ this-> run? 1: 0;
$ Cpage ['param'] = is_array ($ this-> param )? '':"? ". $ This-> param;
Return $ cpage;
}
}

/* Include "../inc/smarty. php ";
$ Cp = new page;


Empty ($ _ REQUEST ['page']) | $ cp-> page = $ _ REQUEST ['page'];
$ Cp-> count = 70000;
$ Cp-> param = $ _ GET;
$ Cp-& gt; size = 100;
$ Cp-> lun = 7;
$ Cp-> run = true;
$ Data = $ cp-> pageDate ();
$ Smarty-> assign ("page", $ data );
$ Smarty-> display ("cpage.html ");
*/
?>

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.