A classic phpmysql paging project_php tutorial

Source: Internet
Author: User
A typical phpmysql paging program. A classic phpmysql paging program this article provides a php paging code, which is a relatively simple and common limit incoming paging function. It also provides the conditional query paging function. This article provides a php paging code by using a classic php mysql paging program. this is a relatively simple and common limit incoming paging, it also provides the conditional query paging function.

A paging program for the mysql tutorial of a classic php Tutorial
This article provides a php paging code, which is a simple and common limit incoming paging code. It also provides the conditional query paging function.
*/

$ Conn = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_password) or die ('server connection error ');
Mysql_select_db ($ mysql_db) or die ("selecting database tutorial errors ");
Mysql_query ("set names 'gbk '");
Function table ($ t)
{
Global $ mysql_table_prefix;
Return $ mysql_table_prefix. $ t;
}


$ SQL = "select * from". table ('keyword'). "where 1 = 1 ";
$ Sql2 = "select count (*) from". table ('keyword'). "where 1 = 1 ";
$ Py = trim ($ _ request ['py']);
If ($ act = "search" and! Empty ($ _ post ['S1'])
{
$ S1 = trim ($ _ post ['S1']); // retrieves search words
$ SQL. = "and (k1 = '$ S1' or k2 =' $ S1 ')";
$ Sql2. = "and (k1 = '$ S1' or k2 =' $ S1 ')";
}
Elseif (! Empty ($ py ))
{
$ SQL. = "and pinyin = '$ PY '";
$ Sql2. = "and pinyin = '$ PY '";
}


$ SQL. = "order by pinyin ";
$ Rscount = mysql_query ($ sql2 );
$ Rscount = @ mysql_fetch_array ($ rscount );
$ Rscount = $ rscount [0]; // obtain the total number of records

$ Page = trim ($ _ get ['Page']); // The current page number.
$ Pagesize = 30; // number of records per page
$ Pagecount = ceil ($ rscount/$ pagesize); // obtain the total number of pages
$ Pageurl = "";
If ($ page <= 1)
{
$ Page = 1;
$ Pageurl. = "homepage previous page ";
} Else
{
$ Pageurl. = "homepage previous page ";
}
If ($ page> = $ pagecount)
{
$ Page = $ pagecount;
$ Pageurl. = "Last page of the next page ";
} Else
{
$ Pageurl. = "Last page of the next page ";
}

$ Start_rs = ($ page-1) * $ pagesize; // start
$ End_rs = $ page * $ pagesize; // end
$ SQL. = "limit {$ start_rs}, {$ end_rs }";
$ Res = mysql_query ($ SQL );

?>

Mysql paging program this article provides a php paging code, which is a simple and common limit incoming paging function. It also provides the conditional query paging function. A sutra...

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.