Learning from Mu-php+mysql--the realization of the principle of pagination

Source: Internet
Author: User

①. The most basic SQL statement

SELECTFROM 表名 LIMIT 开始位置,显示条数

②. The simplest page-paging logic
1. Incoming page numbers

$page$_GET[‘p‘];

2. Incoming data based on page numbers

$host="localhost";$username="Root";$password="";$db="Test";//Connect database$conn= Mysql_connect ($host,$username,$password);if(!$conn){Echo "Database connection Failed";Exit;} Select the database that you want to manipulate mysql_select_db ($db);//Set the database encoding format mysql_query ("SET NAMES UTF8")//write SQL to get paging data$sql="SELECT * from page LIMIT". ($page-1) *Ten.", ten";//Transfer SQL statements to the database$result= mysql_query ($sql);//processing of our dataEcho ' <table border = 1 cellspacing = 0 width = 40%> 'Echo "<tr><td>ID</td><td>NAME</td></tr>" while($row= MYSQL_FETCH_ASSOC (Result)) {Echo "<tr>";Echo "<td>{$row[' id ']}</td> '    Echo "<td>{$row[' name ']}</td> '    Echo "</tr>"; //Echo $row[' id '] .'-'.$row[' name '] .' <br> ';}Echo "</table>"Release the results, close the link mysql_free_result ($result); Mysql_close ($conn);

3. Display Data + pagination bar

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Learning from Mu-php+mysql--the realization of the principle of pagination

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.