A simple MySQL database paging program template

Source: Internet
Author: User
Tags count mysql database

Here is a simple PHP connection to the MySQL database data paging display template. You can modify the information by annotation, the SQL statement inside can be changed.

Pay attention to the analysis and observation of the relevant pagination part of the code to write and implement the way.

<?php
$link = mysql_connect (' localhost ', ' root ', ') or Die (' MySQL database connect error ');
mysql_select_db (' your database ') or Die (' The selected database is not exist ');
?>
Insert your HTML code here,
<?php
$sql = ' SELECT count (*) count from your_table ';
$result = mysql_query ($sql) or Die (Mysql_errno (). ":". Mysql_error (). " \ n ");
$rs =mysql_fetch_object ($result);
$recountCount = $rs->count;
$show = 20;
$totalPage = Ceil ($recountCount/$show);
$page = (isset ($_get[' page ') && $_get[' page ']>=0)? $_get[' page ']: 0;
$isLast = ($page = = ($totalPage-1))? True:false;
$hasNoPre = ($page ==0)? True:false;
$hasNoNext = ($page = = $totalPage-1)? True:false;
$isFirst = ($page ==0)? True:false;
$start = $page * $show;
Mysql_free_result ($result);
?>
Insert your HTML code here,
?
$sql = "SELECT * from Your_table limit $start, $show";
$result = mysql_query ($sql) or Die (Mysql_errno (). ":". Mysql_error (). " \ n ");
while ($rs =mysql_fetch_object ($result)) {
The HTML code in this loop itself is more realistically modified
Echo $rs->art_id;
echo "<br>";
}
Mysql_free_result ($result);
?>

?
$str = "A total of $recountCount records, current section". ($page + 1). " /$totalPage page ";
$str. = $isFirst? "Home": "<a href=\"? page=0\ "> Home </a>";
$str. = $hasNoPre? "Previous page": "<a href=\"? page= ". ($page-1). " \ "> Prev </a>";
$str. = $hasNoNext? "Next page": "<a href=\"? page= ". ($page + 1). " \ "> next page </a>";
$str. = $isLast? "Last": "<a href=\"? page= ". ($totalPage-1). " \ "> Last </a>";
Echo $str;
?>

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.