PHP Paging Display Database related issues, there is code, analysis and analysis

Source: Internet
Author: User
PHP Paging Display database problems, there is code, analysis and analysis
A warning prompt appears the first time you open it. The reason is undefined index:page
How to solve the problem of the transfer of value AH?

The code is as follows


Include ("conn.php");
$perNumber = 10; The number of records displayed per page
$page =$_get[' page '; Get the current page value
$count =mysqli_query ($conn, "SELECT COUNT (*) from user"); Total Records obtained
$rs =mysqli_fetch_array ($count);
$totalNumber = $rs [0];
$totalPage =ceil ($totalNumber/$perNumber); Calculate the total number of pages
if (!isset ($page)) {
$page = 1;
}//If there is no value, assign a value of 1
$startCount = ($page-1) * $PERNUMBER; Start with pagination and calculate the starting record based on this method
$result =mysqli_query ($conn, "select * from User limit $startCount, $perNumber"); Based on the previous calculation, the number of records and records started
while ($row =mysqli_fetch_array ($result)) {
echo "user_id:". $row [' user_id ']. " ";
echo "user_name:". $row [' user_name ']. "
"; Displaying the contents of a database
}
if ($page! = 1) {//pages not equal to 1
?>
"> Previous page
}
for ($i =1; $i <= $totalPage; $i + +) {//Cycle Show page
?>
">
}
if ($page < $totalPage) {//If page is less than total pages, show next link
?>
"> Next page
}
?>






------to solve the idea----------------------
$page =$_get[' page '; Get the current page value
Switch
$page =isset ($_get[' page ')? $_get[' page ': 1; Get the current page value
------to solve the idea----------------------
$page = @$_get[' page ']; Get the current page value

Change into
$page =isset ($_get[' page ')? $_get[' page ': 1; Get the current page value
Yes, but
if (!isset ($page)) {
$page = 1;
}//If there is no value, assign a value of 1
It's superfluous.
  • 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.