Advanced PHP Advanced: To achieve a powerful flip jump function _php Tutorial

Source: Internet
Author: User
We all know that using PHP (as the current mainstream development language) +mysql (and PHP collocation of the best combination) in the Web page implementation of the database data display is very simple and interesting, the database data is very rare in the case of the page display is still satisfactory, but when the database data is very many cases, The display of the page will become very bad, the following is to introduce how to achieve the current page data display number and how to achieve dynamic rollover function.
  
   Here you will find the implementation of the two paging display functions:
-----------------------------------------------------------
Let's introduce the database syntax used in page flipping:
  
MySQL (and PHP collocation of the best combination) _query ("SELECT * from table ORDER BY id DESC");
  
This database statement is more familiar, is used to search for records and displayed in reverse, but not in the paging function, and the following extended syntax is the core function of the implementation of the page:
  
MySQL (and PHP collocation best combination) _query ("SELECT * from table ORDER BY id desc limit $start, $limit");
  
The $start here is the starting line of the database search, $limit from the start line to the beginning of the search to the end of the $limit record, well, with this core function, we can start the paging function;
-----------------------------------------------------------
   The first paging function:
The function described here is the simplest of the page turn function, can only realize the page forward and backward page, the site's very news and Download Center page paging function is this.
  
First of all, introduce the idea of paging function realization:
First determine the current page fixed display of the number of data records, assuming 20 records, set the value of $limit: $limit = 20;
  
When a database record is displayed, it must be displayed starting at the first, so the initial value for setting $start here is 0: $start = 0;
  
The realization of the paging function relies on the dynamic change of the $start, and when the page is $start $limit: $start + $limit, while the $start is subtracted from the $limit when the page is pushed back: $start-$limit;
  
   with the above ideas, you can start to design the program page.php (as the current mainstream development language):
   Sets the number of the current page display (this quantity can be set arbitrarily)
$limit = 20;
  
Initialize database search start record
if (!empty ($start)) $start = 0;
  
MySQL (and PHP collocation of the best combination) _connect ("localhost", "", "");
MySQL (the best combination of PHP collocation) _select_db (database);
  
Set the total number of database records
$result =mysql (the best combination of PHP collocation) _query ("Select * from table");
$num _max=mysql (the best combination with PHP) _numrows ($result);
  
$result =mysql (the best combination with PHP) _query ("SELECT * from table ORDER BY id desc limit $start, $limit);
$num =mysql (the best combination with PHP) _numrows ($result);
  
echo "









";   if (!empty ($num)) {for ($i =0; $i < $num; $i + +) {$val =mysql (the best combination of PHP collocation) _result ($result, $i, "Val");   $val 1=mysql (the best combination with PHP) _result ($result, $i, "val1"); echo " "; }} echo "
Paging function
$val $val 1
";
  
Set Jump to page forward
$prve = $start-$limit;
if ($prve >=0) {
echo "Prve";
}
  
Set Jump to page backward
$next = $start + $limit;
if ($next < $num _max) {
echo "Next";
}
  
echo "
";
?>
  
A pre-turn, post-turn function of the program is completed. But this feature will be cumbersome to handle more data display. The more powerful, more complex paging feature, which I've always called, because I can't find a more appropriate name, will continue here. ^o^

http://www.bkjia.com/PHPjc/509086.html www.bkjia.com true http://www.bkjia.com/PHPjc/509086.html techarticle we all know that PHP (as the current mainstream development language) +mysql (and PHP collocation of the best combination) in the Web page implementation of database data display is very simple and interesting, database data ...

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