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