[Php + mysql] blog paging production ideas, phpmysql paging ideas _ PHP Tutorial

Source: Internet
Author: User
[Php + mysql] blog paging ideas, phpmysql paging ideas. [Php + mysql] blog paging ideas, phpmysql paging ideas 1. First, you need to initialize and set the number of articles displayed on each page $ page_size, total number of articles in mysql database $ arc_size, page count [php + mysql] blog paging ideas and phpmysql paging ideas

1. initialize and set the number of articles displayed on each page $ page_size, total number of articles in mysql database $ arc_size, and number of pages $ page

2. paging formula

(Current page-1) X number of entries per page, number of entries per page
($ Page-1) * $ PageSize, m = $ PageSize indicates that from the table data table, starting from n, the content that ends at n + m is queried. 3. the code for displaying the database content is as follows: $ Conn = @ mysql_connect ("localhost", "root", "liujiang") or die ("An error occurred while connecting to the database server! ");
// Connect to the ly_php_base database
$ OK = @ mysql_select_db ("myblog_base", $ conn) or die ("unable to connect to the database! ");
Mysql_query ("set names 'utf8'"); // solve the problem of inserting Chinese characters in the mysql database. Note that utf8 and In
If ($ OK) {echo "mysql is OK! ";} Else {echo" mysql is failed! ";}
$ Page = $ _ GET ['Page']; // Obtain the current page value.
If (! Isset ($ page) {$ page = 1;} // if no value exists, 1 is assigned.
$ Page_size = 2; // two entries are displayed on each page.
$ Arcs_result = mysql_query ("select count (*) as total from myblog_article"); // The output result is Resource id #4
$ Arc_size = mysql_result ($ arcs_result, 0, "total"); // total number of articles
$ Pagenum = ceil ($ arc_size/$ page_size );
$ Offset = ($ page-1) * $ page_size;
$ SQL = mysql_query ("SELECT * FROM myblog_article WHERE 1 order by id asc limit $ offset, $ page_size ");
// Desc indicates descending order, which means that the order starts from $ offset and is ranked by $ page_size.
If ($ SQL) {echo "query yes";} else {echo "query no ";}
$ Rs = mysql_fetch_array ($ SQL); // Extract data
While ($ rs ){
?>


Article title:


Article type:


Introduction:


Upload time:


Author: [ ] Page



$ Rs = mysql_fetch_array ($ SQL );
}
For ($ I = 1; $ I <= $ pagenum; $ I ++ ){


$ Show = ($ I! = $ Page )? "$ I ":" $ I";
Echo $ show ."";

}
?>

First, you need to initialize the number of articles displayed on each page $ page_size, total number of articles in mysql database $ arc_size, number of pages...

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.