After using PHP to make a blog, for the pagination code really let me this 0 basis of the people to pay some old strength, finally studied the day after night, reluctantly wrote a simple code, reluctantly can use. This is the first version and will be updated to be paged in the same way as a class. Cheer Up ~
<?php //set the number of articles displayed per page $pagesize=5;//determine the parameters of the pages P @ $p =$_get[' P ']?$_get[' p ']:1;//data pointer $offset = ($p-1) *$ pagesize;//Query the data displayed on this page $query = "select * from ' Arts ' order by id DESC limit $offset, $pagesize "; //query data $res =mysql_query ($query); while ($row =mysql_fetch_array ($res)) { //cycle started? ><div class= "Nav_new" > <ul> <li><a href= "view.php?id=<?php echo $row [' Id ']?> ' target= "_blank" ><?php echo $row [' title ']?></a></li> </ul> </div><?php }?> <div style= "width:990px; height:15px; margin-top:15px;text-align:right;" ><?php //calculate the total number of messages $count_result=mysql_query ("select count (*) as count from Arts "); $count _array=mysql_fetch_array ($count _result);//Calculation totalPage $pagenum=ceil ($count _array[' count ']/$pagesize);//output individual pages and links if ($pagenum >1) { for ($i =1 , $i <= $pagenum, $i + +) { if ($i = = $p) { echo ' [', $i, '] '; }else{ echo " ;".‘ <a href= "index.php?p=", $i, ' > ', $i, ' </a> '; } }}echo " ". ' Total ', $count _array[' count '], ' article ';? > </div>
This article from the "7C" blog, reproduced please contact the author!
PHP Easy page Pagination code