PHP simple paging implementation

Source: Internet
Author: User
PHP simple paging implementation The key point of a program is page number acquisition.

 "; $ Url = $ _ SERVER [" PHP_SELF "]; $ pageNow = isset ($ _ GET ['pagenow'])? $ _ GET ['pagenow']: 1; $ start = ($ pageNow-1) * $ every; $ allsql = "select * from {$ table };"; // die (); // $ SQL = "select * from test;"; $ rest = $ conn-> query ($ allsql ); $ field = $ rest-> fetch_fields (); $ fieldNum = count ($ field); // number of fields // obtain the data volume $ rowNum = $ rest-> num_rows; // echo "number of records :". $ rowNum; $ allpage = ceil ($ rowNum/$ every); // echo "---- every page is divided into $ every ". "$ allpage ". "page
"; // $ PageNow = ($ pageNow-1) * $ every; echo" "; // Echo" add test info table "; // echo" $ pageNow "." page "; echo" "; For ($ I = 0; $ I <$ fieldNum; $ I ++) {echo" ";} Echo" "; // Display the page $ SQL =" select * from $ table limit $ start, $ every; "; // echo $ SQL; $ newRest = $ conn-> query ($ SQL); while ($ row = $ newRest-> fetch_row () {echo" "; For ($ j = 0; $ j <$ fieldNum; $ j ++) {echo" ";} Echo" ";} Echo"
". $ Field [$ I]-> name ."
". $ Row [$ j]."
"; Echo"

"; Echo"

"; Echo" $ pageNow/$ allpage "; echo" homepage "; if ($ pageNow = 1) {echo" previous page ";} else {$ pagePre = $ pageNow-1; echo "previous page";} // echo "previous page"; // echo "next page"; if ($ pageNow = $ allpage) {echo "next page ";} else {$ pageNext = $ pageNow + 1; // echo "$ pageNow"; echo "next page";} echo "last page"; echo"

"; Echo" "; Echo"Select page"; For ($ I = 1; $ I <= $ allpage; $ I ++) {echo"$ I";} Echo" "; Echo"

"; Echo"

"; $ Conn-> close () ;}// actually use a test data table echo pagef (10, 'test');?>

// Css file

*{padding: 0px;  margin: 0px;}.center{text-align: left;        color: red;        text-indent: 500px;}#info{color: DodgerBlue;}.table{       margin-left: auto;       margin-right: auto;       width: auto;       text-align: center;       color: royalblue;       border: 0;       }.td{width: 150px;    /*text-indent: 10px;*/    text-align: left;    font-size: 14px;}#td{color: #555;}tr:hover{background-color: DodgerBlue;}.info{text-align: center;      color: red;}.link{color: blue;      text-decoration: none;      text-align: center;      font-size: 12px;}.h3{text-align: center;    }#pclass{width: 100%;          height: 30px;          margin-top: 10px;          font-size: 18px;          /*background: coral;*/          }#center{width: 27%;        /*display: inline-block;*/        height: 30px;        margin-left: auto;        margin-right: auto;        /*background: orange;*/      }.fy{    /*background: DodgerBlue;*/    height: 30px;    line-height: 30px;    display: inline-block;    float: left;    color: DodgerBlue;    padding-left: 5px;    text-decoration: none;    text-align: center;   }.option{width: 80px;        height: 30px;        background: white;        float: left;        border: 2px solid DodgerBlue;        display: inline-block;}.button{width: 56px;        float: left;        color: white;        background: DodgerBlue;        height: 30px;        border: 0px;        border-radius: 0px;        display: inline-block;}

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.