PHP Easy page Pagination code

Source: Internet
Author: User

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, ' &nbsp;</a> ';         }    }}echo  "&nbsp;&nbsp;". ' Total ', $count _array[' count '], ' article ';? >        </div>


This article from the "7C" blog, reproduced please contact the author!

PHP Easy page Pagination code

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.