Php+mysql Page Paging Code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags .net asp asp.net code function get mysql mysql tutorial

In the PHP tutorial +mysql Tutorial Database tutorials in the paging code than the previous ASP tutorials, the ASP.net tutorial is relatively easy, because MySQL support limit,0,n so that you can easily and quickly get the records to read, so let's look at the example

function GetPage ($talbe, $choose, $url) {


Global $page, $db, $sortname;


$query = $db->query ("select * from $talbe $choose");


$total = $db->num_rows ($query);


$totalpage =ceil ($total/25);


$nextpage = $page +1;


$uppage = $page-1;


if ($nextpage > $totalpage) $nextpage = $totalpage;


if ($uppage <1) $uppage = 1;


$showpage = "Total <b><font color= ' #FF0000 ' > $total </font></b> record, total <b><font color= ' #FF0000 ' > $totalpage </font></b> page, currently <b><font color= ' #FF0000 ' > $page </font>< /b> Page


<b><font color= ' #FF0000 ' >◇</font></b><a href= '? $url &page= $uppage &sortname=$ Sortname ' > Prev </a><b><font color= ' #FF0000 ' >◇</font></b><a href= '? $url & page= $nextpage &sortname= $sortname ' > next page </a><font color= ' #FF0000 ' ><b>◇ ';


return $showpage;


}


function Reto ($msg, $url = ') {


Global $comeurl;


if (! $url) $url = $comeurl;


return "<table width= ' 100% ' cellspacing= ' 1 ' cellpadding= ' 3 ' bgcolor= ' #CCCCCC ' >


<tr bgcolor= ' #FFFFFF ' >


<td>


<div align= ' center ' ><font size= ' +6 ' ><b><font size= ' 5 ' ><a href= ' $url ' >& Lt;font color= ' #993300 ' > $msg </font></a></font></b></font></div>


</td>


</tr>


</table> ";


}


through the page of the code we can see the original PHP page is very simple, as long as get[page] page, the current page, and then use the $page* $pagesize to start, after the end of the $pagesize OK. The MySQL statement is $sql = "SELECT * FROM t limit $page * $pagesize, $pagesize";


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.