PHP page Code learning sample Sharing _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
Header ("Content-type:text/html;charset=utf-8");
Database connection
$conn = mysql_connect ("localhost", "root", "111") or Die ("Not connnected:". Mysql_error ());
mysql_select_db ("Test", $conn);
mysql_query ("Set names UTF8");

Query the total number of rows of data
$sql 1 = "SELECT count (*) from user";
$ret 1 = mysql_query ($sql 1);
$row 1 = mysql_fetch_row ($ret 1);
$tot = $row 1[0];

How many rows of data per page
$length = 5;
Total pages
$totpage = Ceil ($tot/$length);

Current page
$page = @$_get[' P ']? $_get[' P ']: 1;
Limit limit
$offset = ($page-1) * $LENGTH;

echo "

";
echo "

PHP padding

";
echo "




Display the queried data in a table
$sql 2 = "SELECT * from the user order by ID limit {$offset}, {$length}";
$ret 2 = mysql_query ($sql 2);
while ($row 2 = MYSQL_FETCH_ASSOC ($ret 2)) {
echo "




echo "

"; echo " "; echo " "; echo " "; echo " "; echo " "; "; echo " "; echo " "; }
IDUSERPASS
{$row 2[' id '} {$row 2[' name '} {$row 2[' pass '}
";

Previous page and next page
$prevpage = $page-1;
if ($page >= $totpage) {
$nextpage = $totpage;
} else {
$nextpage = $page + 1;
}

Jump
echo "

Previous Page | next page

";
echo " ";

Core points:

<1> "$sql 2 =" SELECT * from the user order by ID limit {$offset}, {$length} ";", the relationship between $offset, $length, and number of pages.

<2> How to get the previous and next pages, and the tipping point.

http://www.bkjia.com/PHPjc/825276.html www.bkjia.com true http://www.bkjia.com/PHPjc/825276.html techarticle Copy the code as follows: PHP header ("Content-type:text/html;charset=utf-8");//database connection $conn = mysql_connect ("localhost", "root", "111") or Die ("Not connnected:". mysql ...

  • 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.