PHP self-training project-digital paging effect

Source: Internet
Author: User
: This article mainly introduces the digital paging effect of PHP self-training projects. if you are interested in PHP tutorials, refer to it. Learning points:
1. LIMIT usage
2. various parameters
3. hyperlink call

First, set the digital paging module in the file. my file is (blog. php)

// Paging module $ _ page =$ _ GET ['Page']; $ _ pagesize = 10; $ _ pagenum = ($ _ page-1) * $ _ pagesize; // obtain the total data on the home page $ _ num = mysql_num_rows (_ query ("SELECT tg_id FROM tg_user"); $ _ pageabsolute =$ _ num/$ _ pagesize;

It should be noted that when the set is retrieved in the database

// We must re-read the result set each time instead of executing the SQL statement again.
$ _ Result = _ query ("SELECT tg_username, tg_sex, tg_face FROM tg_user order by tg_reg_time desc limit $ _ pagenum, $ _ pagesize ");
Set the effect of pagination loop

    $i+1).'">'.($i+1).''; }else{ echo '
  • $i+1).'">'.($i+1).'
  • '; } } ?>

Corresponding CSS

#page_num {height:20px;clear:both;padding:10px 0;position:relative;}#page_num ul {position:absolute;right:30px;height:20px;}#page_num ul li {float:left;width:26px;height:20px;}#page_num ul li a {display:block;width:20px;height:20px;line-height:20px;border:1px solid #333;text-align:center;text-decoration:none;}#page_num ul li a:hover,#page_num ul li a.selected {background:#666;font-weight:bold;color:#fff;}

The error may occur due to the encoding. the solution is

// Paging module if (isset ($ _ GET ['Page']) {// solution to an error that no longer occurs within the data range $ _ page = $ _ GET ['Page']; // whether it is null, less than 0, or not a number. // If one of them is, it is equal to 1if (empty ($ _ page) | $ _ page <0 |! Is_numeric ($ _ page) {$ _ page = 1;} else {$ _ page = intval ($ _ page); // if it is a number, but decimal, then convert $ _ page = intval ($ _ page); to an integer} else {$ _ page = 1 ;}$ _ pagesize = 10; $ _ num = _ num_rows (_ query ("SELECT tg_id FROM tg_user"); if ($ _ num = 0) {$ _ pageabsolute = 1 ;} else {$ _ pageabsolute = ceil ($ _ num/$ _ pagesize);} // when the page number is greater than the total page number, returns the last page of the total page number. if ($ _ page >$ _ pageabsolute) {$ _ page =$ _ pageabsolute ;} $ _ pagenum = ($ _ page-1) * $ _ pagesize;

The above introduces the digital paging effect of the PHP self-training project, including some content, and hopes to help those who are interested in the PHP Tutorial.

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.