革命往事 电影下载:asp长文章分页显示代码
来源:百度文库 编辑:高校问答 时间:2024/05/03 00:10:52
但是当遇到图片的时候就回出现错误,请问一下这个问题该怎么解决呢 ?
<%
sub autopage()
Maxpagelen=1000
content=ubbcode(rs("content"))
ArticleID=rs("ArticleID")
contentlen=len(content)
page=request.QueryString("page")
if contentlen<=Maxpagelen then
response.Write content
else
if page="" then
page=1
else
page=Cint(page)
end if
if pageNumber*MaxPagelen<contentlen then
PageNumber=PageNumber+1
end if
PageNumber=int(contentlen/Maxpagelen)+1
if page<1 then page=1
if page>PageNumber then page=PageNumber
if page=1 then
BeginPoint=1
else
BeginPoint=MaxPagelen*(page-1)+1
end if
if page=PageNumber then
EndPoint=contentlen
else
EndPoint=MaxPagelen*page
if EndPoint>=ContentLen then
EndPoint=ContentLen
end if
end if
end sub
%>
我用的这个函数,可以自动分页了,但是如果是遇到图片就回出错了
代码贴出来 否则白扔100分
http://www.72598.com/article5.asp?article_id=955
为了版美观,有时需要将一编较长的文章分页来显示,这时只好将文章分多次存入数据库,极不方便
本人见过多种自动分页代码,感觉上不是很理想
偶的思路是统计文章的所有行数,按指定行数输出显示内容并生成分页导航
如有不足之处望写信告诉作者
演示地址:http://mail-1.fz169.net/wh/sys/page/
<%
'#######################
'程序名:ASP文章自动分页
'编 写: 网 海 求 生 者
' Q Q:54883661 E-mail:
' wuyingke5155@163.com
'#######################
'连接数据库:
on error resume next
dim conn,connstr,dbpath
dbpath=server.mappath("web.mdb") '数据库文件名
set conn=server.createobject("adodb.connection")
connstr="driver={microsoft access driver (*.mdb)};dbq="&dbpath&";"
conn.open connstr
if err.number<>0 then
response.write err.description
err.clear
response.end
end if
sub connclose()
conn.close()
set conn=nothing
end sub
'读取数据:
dim rs,sql,conntent,title,id
id=1'trim(request("id")) '上页传来的ID值,为了调试方便此ID值临时赋为1
set rs=server.createobject("adodb.recordset")
sql="select * from news where id="&cint(id)
rs.open sql,conn,1,1
if not (rs.eof and rs.bof) then
content=rs("content") '读取内容
title=rs("title") '读取标题
end if
if err.number<>0 then
response.write err.description
err.clear
response.end
end if
rs.close
set rs=nothing
call connclose()
'分页处理部分:
'---------------------主代码开始--------------------------
dim page,pagecount,thispage,linenum,allline
const pageline=10 '每页显示10行
linenum=split(content,"<br>") '本例为计算字符串<br>标记的个数
allline=ubound(linenum)+1 '全文<br>(换行标记)总数
pagecount=int(allline\pageline)+1 '计算总页数
page=request("page")
if isempty(page) then
thispage=1
else
thispage=cint(page)
end if
response.write "<title>"&title&"</title><b>"&title&"</b><hr>"
for i=0 to allline
if i+1>thispage*pageline-pageline and i<thispage*pageline then
response.write linenum(i) &"<br>" '输出分页后的内容
end if
next
response.write chr(13)&"<hr>"
response.write "<p align='center'>总共"&allline&"行 "&pagecount&"页 每页"&pageline&"行 "
for i=1 to pagecount
if thispage=i then
response.write i & " "
else
response.write "<a href='?page="&i&"&id="&id&"'>"&i&"</a> " '输出所有分页链接
end if
next
'---------------------主代码结束--------------------------
%>
另一方法:
http://www.szasp.net/Blog/SeeTheBlog.asp?NewsId=2305
原理:设置一个限量的字符数,按节点计算,如果一个节点的字符数未超过,那它与下一个节点合并。 直到超过这个限量,就显示出来。
JavaScript脚本部分
======================
function submitPostIfRame(mode){
var sMarkup = doc_html.getHTML();; //从html编辑器中取数据
with(document.forms[0]){
doc_html.document.open();;
doc_html.document.write(sMarkup);;
doc_html.document.close();;
doc_html.document.body.innerHTML = sMarkup;;
var oBody=doc_html.document.body;;
var oHTML="";;
for(var i=0;;i if(i!=oBody.childNodes.length-1){
if(oBody.childNodes[i].nodeType==3){
oHTML+=oBody.childNodes[i].nodeValue+"{#CMS-PAGINATION-SYMBOL#}";;
}else{
oHTML+=oBody.childNodes[i].outerHTML+"{#CMS-PAGINATION-SYMBOL#}";;
}
}else{
if(oBody.childNodes[i].nodeType==3){
oHTML+=oBody.childNodes[i].nodeValue;;
}else{
oHTML+=oBody.childNodes[i].outerHTML;;
}
}
}
news_content.value = oHTML
}
return true;;
}
ASP脚本部分
===============
Function calculate_pagination(strContent, pSize)
On Error Resume Next
Dim aCon, intfor, intCount, strTemp, strTemp2
aCon = Split(strContent, "{#CMS-PAGINATION-SYMBOL#}", -1, 1)
intCount = UBound(aCon)
strTemp = ""
strTemp2 = ""
Page = 1
For intfor = 0 To intCount
strTemp = strTemp & aCon(intfor)
strTemp2 = strTemp2 & RemoveHTML(aCon(intfor))
'strTemp2 = strTemp2 & aCon(intFor)
If Len(strTemp2) 〉= pSize Then
Page = Page + 1
strTemp = ""
strTemp2 = ""
End If
Next
'If strTemp2 〈〉 "" Then Page = Page - 1
calculate_pagination = Page
If Err.Number 〈〉 0 Then
calculate_pagination = 1
Err.Clear
End If
End Function
Function get_page_text(strContent, pagenum, totalpage, pSize)
aCon = Split(strContent, "{#CMS-PAGINATION-SYMBOL#}", -1, 1)
intCount = UBound(aCon)
strTemp = ""
strTemp2 = ""
Page = 1
For intfor = 0 To intCount
strTemp = strTemp & aCon(intfor)
strTemp2 = strTemp2 & RemoveHTML(aCon(intfor))
'strTemp2 = strTemp2 & aCon(intFor)
If Len(strTemp2) 〉= pSize Then
If pagenum = Page Then
get_page_text = strTemp
Exit For
End If
Page = Page + 1
strTemp = ""
strTemp2 = ""
End If
Next
If strTemp2 〈〉 "" And pagenum 〉 Page - 1 Then get_page_text = strTemp
End Function