Using ASP to implement long articles page display with page breaks

Source: Internet
Author: User
Long article page with page break to display, want to use ASP also realize this function, you can find only the method of paging according to the word count, but there is a bug in this method, that is, if you have UBB code in the content of the article, it is very easy to create a paging between, or simply break [code] into [Co and de] , so the article will show an error.

The following steps will be fully implemented.

First step:

In accordance with the normal article system to do all the way down, the background of the article to add, the article's search, and the detailed page of the article, are the general mode of operation, here without description, please refer to the relevant posts. Just add the page break where you want it to be paged: "| | |" (Of course this symbol you can use, such as: [Page], &&&, ###, @@@., as long as it does not appear in the article to the normal display of the line. )

I used four pages, input page (index.asp), Input complete page (add.asp), Article List page (view.asp), Article content page (display.asp), the first three are not to deal with the page, look at the picture below I think the general bird will do, the key is the last displasy.asp, all the implementation of pagination code here.

Step Two:

In the text of the content of the dynamic Data part of the hands and feet, the following is the Code and interpretation:

  <%
' here to process the received paging parameters to display the contents of page
' The following two sentences is if there is no page this argument is to let the variable pagenum to display the value of the first page: 0
If Request (" Page "=" "Then
pagenum=0
" Otherwise assign the variable to the argument in the page passed, to display the other page
else
pagenum=request ("page")
End If
%
<%
' If you add optional execution UBB code, you can add the following code
' RS (' Noubb ') is the database about disabling UBB fields, 0 is disabled, 1 is executing
if RS ("Noubb") =0 then
' To avoid errors associated with the content of the article, use the Replace function to put the paging code "| | |" Plus a full-width
' rs ("content") is a field in the body of the database, plus UBB or disable UBB
Content=replace ((unhtml (RS ("content")), "| | |", "| | | ")
Elseif rs (" Noubb ") =1 then
Content=replace ((Ubb (" Content "))," | | | "," | |
End If
%>
<%
' Here's the key. ' We use the Split function to separate the articles into variables content
Contentstr=split (content, "| | |")
' in accordance with the variable that you just obtained from the URL parameter to display that side, loop to display a page
for I=pagenum to Pagenum
%>
<!--here will be the text of the article;
<%= Contentstr%>
<% Next%>

</td>
</tr>
<tr>
<TD height= "class=" "ClassName" > This paper is divided into
<%
' Pagination place, with UBound (CONTENTSTR) to get the article is divided into several pages, note that this is starting from 0, so the total number of pages need to add 1
For p = 0 To UBound (CONTENTSTR)

' Link or this page, but after the article ID parameter also add a paging parameter: page
%>
<a href= "Display.asp?id=<%=rsquest" ("ID")%>&page=<%=p%> "class=" "><%=p+1%></a>
<% Next%> Page


Very simple, if the comments are deleted, only 15 lines of code, but also to be processed, so that it can have the previous page, the next page and the current page outstanding features on the perfect.

has been tested, unless the article appears that page break, otherwise all types will not go wrong, of course, you can put | | | The number of increase, such as: | | | | |, and then six "|" The following in the article appears all right, but more than six will be paginated, choose a good page break on it



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.