PHP Example Tutorial: Implementing a Dynamic rollover feature _php tutorial

Source: Internet
Author: User
   Fire Station College (bkjia.com) PHP tutorialIt is very simple and interesting to use Php+mysql to display the database data in the Web page, while the database data is very small, the page display is still satisfying, but when the database data is very much, the display of the page will become very bad. Here is how to achieve the current page data display number and how to achieve dynamic rollover function.

This article describes the implementation of the two flip-page display features:

Let's introduce the database syntax used in page flipping:

mysql_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_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 kind of 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 of the very news and Download Center of the paging function is this. First of all, introduce the idea of paging function implementation, first determine the current page fixed display data record number, 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 the $limit is added regularly: $start + $limit, while the front page $start subtract $limit: $start-$limit;

With the above ideas, you can start to design the program page.php:

The following is the referenced content:

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_connect ("localhost", "", "");
mysql_select_db (database);

Set the total number of database records
$result =mysql_query ("SELECT * from table");
$num _max=mysql_numrows ($result);

$result =mysql_query ("Select * FROM table ' ORDER BY id desc limit $start, $limit);
$num =mysql_numrows ($result);

echo "

if (!empty ($num)) {
for ($i =0; $i < $num; $i + +) {
$val =mysql_result ($result, $i, "Val");
$val 1=mysql_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.:)

    • Total 3 Pages:
    • Previous page
    • 1
    • 2
    • 3
    • Next page

http://www.bkjia.com/PHPjc/364213.html www.bkjia.com true http://www.bkjia.com/PHPjc/364213.html techarticle Fire Station College (liehuo.net) PHP tutorial with Php+mysql in the Web page to implement the database data display is very simple and interesting, the database data is very rare in the case of the page display or let people full ...

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