Simple paging for MySQL table data using PHP

Source: Internet
Author: User

PHP simple paging for MySQL table data

<?php  $conn =mysql_connect ("127.0.0.1", "root", ' 123456 ')  or die ("Database connection Failed"); mysql_select_db ("Ym mysql_query ("Set names utf8");//Gets the number of rows of data $all=mysql_num_rows (mysql_query ("Select * from  t1 ")     //define the required parameters for paging $lenght=5;                               //display per page @ $page =$_get[' page ']?$_get[' page ']:1;    //current page $offset= ($page-1) * $lenght;               //Start row number per page $allpage =ceil ($all/$lenght);             //all pages-Total pages $ prepage= $page -1;                        //prev        if ($page ==1) {      $prepage=1;                          //Special is the current page is 1 o'clock the previous page is 1    } $nextpage = $page +1; if ($page = = $allpage) {     $nextpage = $allpage;                 //Special is that the last page is the total page when the page is the total page     } $sql = " select * from t1 order by id limit {$offset},{$lenght} "; $rest =mysql_ Query ($sql);echo  "SQL statement:" $sql. " <br/> ";echo " The total number of pages is: ". $all." Page <br/> ";echo " The current page is: ". $page." <br/> ";echo " <center><table width=500 border=1px /> "while ($detail =mysql _fetch_row ($rest)) {// echo  "<pre>",// print_r ($detail);// echo  "</pre>"; echo  "<tr/>";echo  "<td> $detail [0]</td>";echo  "<td> $detail [1]</td> ";echo " <td> $detail [2]</td> ";echo " <tr/> ";} echo  "</table></center>";echo  "<center><a href= ' code8.php?page=1 ' > Home |"; echo  "<a href= ' code8.php?page={$prepage} ' > previous page </a>|"; echo  "<a href= ' code8.php?page={$nextpage} ' > next page </a>|"; echo  "<a href= ' code8.php?page= $allpage ' > Last </center>";     ?>


Simple paging for MySQL table data using PHP

Related Article

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.