Php entry-level paging functions-PHP source code

Source: Internet
Author: User
Tags mysql tutorial
This is a simple and practical php paging code. If you are a beginner of php, let's take a look at this practical paging code. This is a simple and practical php paging code. If you are a beginner of php, let's take a look at this practical paging code.

Script ec (2); script

The Code is as follows:

Function page ($ SQL, $ pagesize = 10, $ class = ""){

If (! Is_string ($ SQL) {return 0; exit ;}
$ Result = mysql tutorial _ query ($ SQL );
If (! $ Result) {return 0; exit ;}
If (! $ Recordnum = mysql_num_rows ($ result) {return 0; exit ;}
$ Totalpage = ceil ($ recordnum/$ pagesize );
$ Page = (int) $ _ get ['page'];
If ($ page <= 1) $ page = 1;
If ($ page >=$ totalpage) $ page = $ totalpage;
$ Recordno = ($ page-1) * $ pagesize;
$ SQL. = "limit $ recordno, $ pagesize ";
$ Result = mysql_query ($ SQL );
$ Url = $ _ server ["php_self"];

If ($ page = 1) $ str = "homepage | previous page ";
Else $ str. = "homepage | previous page ";
If ($ page = $ totalpage) $ str. = "| next page | last page ";
Else $ str. = "| next page | last page ";
$ Str. = "current $ page $ totalpage ";
Return array ($ result, $ str );
}
// Call Method

$ SQL = "select * from images order by imid ";
$ Result = page ($ SQL, 16 );

/*
The simple principle is to read the corresponding records in the uploaded database tutorial, so that the page is displayed.
*/

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.