Php+mysql Realizing paging

Source: Internet
Author: User

First, let's create a table to hold the data

I realized by using the native Php+mysql. All mixed up together.

<?phpheader (' Content-type:text/html;charset=utf-8 '); include ('./sqldb.php '); $sql = "SELECT * from test ORDER by ID                Desc "; $result =mysql_query ($sql); $num =mysql_num_rows ($result);  Total pages $pagesize=5; Page size $pagecount=ceil ($num/$pageSize);//Total pages $pageno=isset ($_get[' page ')? $_get[' page ']:1; Page $pagenext= $pageNo +1;//next $pageprev= $pageNo -1;//previous page//determine page number crossed if ($pageNext > $pageCount) $pageNext = $pageCount; if ($pagePrev <1) $pagePrev =1;if ($pageNo > $pageCount) $pageNo = $pageCount, if ($pageNo <1) $pageNo =1; $offset = ($       PAGENO-1) * $pageSize; Offset Mysql_data_seek ($result, $offset);//Move the result pointer to offset? ><style type= "Text/css" >tr{background-color:# Ffffff font-size:12px;} td{text-align:center;height:30px;} </style><table width= "100%", "bgcolor=" #333666 "cellspacing=" 1 "><tr><td>ID</td>< Td> name </td><td> permissions </td></tr><tr><?php for ($i =0; $i < $pageSize; $i + +): $row =my SQL_FETCH_ASSOC ($result); if ($row):? ><td><?php echo $row [' ID ']?></td><td><?php echo $row [' Name ']?&GT;&LT;/TD&GT;&LT;TD ><?phpswitch ($row [' flag ']) {case ' 1 ': echo "teacher"; Break;case ' 2 ': echo "Professor"; Break;default:echo "student"; break;}? ></td></tr><?phpendif;endfor;?  &GT;&LT;TR&GT;&LT;TD colspan= "3" > <?php echo $num?> total <?php echo $pageCount?> page <?php echo per page $pageSize ?> <a href= "page.class.php?page=1" > Home </a><a href= "page.class.php?page=<?php echo $pagePrev? > > First page </a><a href= page.class.php?page=<?php echo $pageNext?> > Next </a><a href= page.class.php?page=<?php echo $pageCount?> "> last page </a></td></tr></table>

  

Php+mysql Realizing paging

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.