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