主题:  请教文章内分页的问题!

lalagu

职务:普通成员
等级:1
金币:0.0
发贴:24
#12007/1/25 10:46:41
代码如下,链接是shownews.asp?news_id=21,不知道哪里出了问题,请大家帮看看,在线等.............................
<%
'连接数据库:
on error resume next
'dim conn,connstr,dbpath
dbpath=server.mappath("mdb/onedoo.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 "<font color=red>"&err.description&"</font>"
err.clear
response.end
end if
sub connclose()
conn.close()
set conn=nothing
end sub

'读取数据:
dim rs,sql,conntent,title,id
id=trim(request("news_id") '上页传来的ID值,为了调试方便此ID值临时赋为1
set rs=server.createobject("adodb.recordset"
sql="select * from news where news_id="&cint(id)
rs.open sql,conn,1,1
if not (rs.eof and rs.bof) then
content=ubb2html(formatStr(autourl(rs("news_content")),true,true) '读取内容
title=rs("news_title" '读取标题
end if
if err.number<>0 then
response.write "<font color=red>"&err.description&"</font>"
err.clear
response.end
end if
rs.close
set rs=nothing
call connclose()

'分页处理部分:

'---------------------主代码开始--------------------------

dim page,pagecount,thispage,linenum,allline

const pageline=25 '每页显示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
'---------------------主代码结束--------------------------
%>