Questions about webpage pagination

Source: Internet
Author: User
I first learned how to output the title by page. what I want to ask is how to implement paging with an article, that is, a fixed number of words are output per page. & Nbsp; this is the page I have referenced. it is divided by title. & Lt ;? Php & nbsp; include & quot; config/db_mysql.php & quot; $ pa about webpage paging
As for webpage paging, I first learned how to make the title output by page. what I want to ask is how to implement paging with an article, that is, to output a fixed number of words per page.

This is the page I have referenced. it is divided by title.
Include "config/db_mysql.php ";
$ Pagesize = 8; // defines how many records are displayed on each page
$ Page = isset ($ _ GET ["page"])? Intval ($ _ GET ["page"]): 1; // defines the initial page Value. if the page passed by get is empty, page = 1,
$ Total = mysql_num_rows (mysql_query ("select id from news"); // execute the query to obtain the total number of records
$ Pagecount = ceil ($ total/$ pagesize); // calculate the total number of pages
If ($ page> $ pagecount ){
$ Page = $ pagecount; // Check the submitted page.
}
If ($ page <= 0 ){


$ Page = 1; // Check the submitted page.
}
$ Offset = ($ page-1) * $ pagesize; // offset
$ Pre = $ page-1; // Previous page
$ Next = $ page + 1; // next page
$ First = 1; // page 1
$ Last = $ pagecount; // last Page
$ SQL = "select * from 'news' order by id desc limit $ offset, $ pagesize"; // execute the query
$ Result = mysql_query ($ SQL );
While ($ arrn = mysql_fetch_array ($ result ))
{
Echo "". "". $ arrn ['title']. "". "";
Echo "". "". $ arrn ['Time']. "". "";
Echo"
";
Echo"
";

}
?> Home Page> Previous Page> Next Page> last page
I tried to rewrite the code if I wanted to change the value of $ total so that I could output it by page.


So we made the following changes:
$ Id = $ _ POST ["id"];
$ SQL = "select * from 'news' where id = $ id ";
$ Result = mysql_query ($ SQL );
While (mysql_fetch_query ($ result ))
{
$ Total = strlen ($ arrn ['content']); // obtain the total number of articles. However, if there is a problem, the Chinese character occupies two characters, therefore, the output is always a matter of two times.
}

$ Pagesize = 8; // defines how many records are displayed on each page
$ Page = isset ($ _ GET ["page"])? Intval ($ _ GET ["page"]): 1; // defines the initial page Value. if the page passed by get is empty, page = 1,
$ Total = mysql_num_rows (mysql_query ("select id from news"); // execute the query to obtain the total number of records
$ Pagecount = ceil ($ total/$ pagesize); // calculate the total number of pages
If ($ page> $ pagecount ){
$ Page = $ pagecount; // Check the submitted page.
}
If ($ page <= 0 ){


$ Page = 1; // Check the submitted page.
}
$ Offset = ($ page-1) * $ pagesize; // offset
$ Pre = $ page-1; // Previous page
$ Next = $ page + 1; // next page
$ First = 1; // page 1
$ Last = $ pagecount; // last Page
$ SQL = "select * from 'news' order by id desc limit $ offset, $ pagesize"; // execute the query
$ Result = mysql_query ($ SQL );
While ($ arrn = mysql_fetch_array ($ result ))
{
Echo $ arrn ['content'];

}
?> Home Page> Previous Page> Next Page> last page
There will be something on the first page, and it will become a jump, and this page cannot be displayed


------ Solution --------------------
Pagination is a page that is manually inserted by the person who entered the article into the code using regular expressions.
------ Solution --------------------
It should be because a paging character is inserted in the article, and JS can be used in the client for paging.

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.