请问一个菜鸟问题,关于分页

Tomato77 2005-04-21 01:45:31
我遍历根目录下的所有文件,显示在页面上,代码如下:

<%
set MyFSO = Server.CreateObject("Scripting.FileSystemObject")
set MyFolder = MyFSO.GetFolder(Server.MapPath("/"))
set MyFiles = MyFolder.Files
%>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td><center><font color="#CC0000">序号</font></center></td>
<td><center><font color="#CC0000">文件名</font></center></td>
<td><center><font color="#CC0000">类型</font></center></td>
<td><center><font color="#CC0000">上传日期</font></center></td>
</tr>
<%
intMun=1
For Each MyFile in MyFiles '文件信息列表
f = Server.MapPath("\"&MyFile.Name)
%>
<tr>
<td><%=intMun%></td>
<td><A Href="/<%=MyFile.Name%>"><%=MyFile.Name%></A></td>
<td><%=MyFile.Type%></td>
<td><%=MyFile.DateCreated%></td>
</tr>
<%
intMun=intMun+1
Next
%>
</table>


请问如何用分页的方式显示?例如每页10行地显示。最好有导航栏。谢谢!
...全文
121 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
要不就是我想了过多的排序方法,呵呵,最近脑袋想得太多了
  • 打赏
  • 举报
回复
楼上这么写的,我觉得有bug的,我没测试过,我觉得fso是无序的,不可能保证都是这么排列的吧??
scoutlin 2005-04-21
  • 打赏
  • 举报
回复
<%
set MyFSO = Server.CreateObject("Scripting.FileSystemObject")
set MyFolder = MyFSO.GetFolder(Server.MapPath("/"))
set MyFiles = MyFolder.Files
recCount=MyFiles.count
pagesize=5
pagecount=recCount/pagesize
if pagecount<>int(pagecount) then pagecount=pagecount+1
pagecount=int(pagecount)
Page=request("page")
if page="" or not isnumeric(page) then page="1"
page=cint(page)
if page<1 then page=1
if page>pagecount then page=pagecount
sp=(page-1)*pagesize+1
ep=sp+pagesize
%>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td><center><font color="#CC0000">序号</font></center></td>
<td><center><font color="#CC0000">文件名</font></center></td>
<td><center><font color="#CC0000">类型</font></center></td>
<td><center><font color="#CC0000">上传日期</font></center></td>
</tr>
<%
intMun=1
For Each MyFile in MyFiles '文件信息列表
if intMun>=sp and intMun<=ep-1 then
f = Server.MapPath("\"&MyFile.Name)
%>
<tr>
<td><%=intMun%></td>
<td><A Href="/<%=MyFile.Name%>"><%=MyFile.Name%></A></td>
<td><%=MyFile.Type%></td>
<td><%=MyFile.DateCreated%></td>
</tr>
<%
end if
intMun=intMun+1
Next
%>
</table>
<a href='?page=1'>第一页</a>
<a href='?page=<%=page-1%>'>上一页</a>
<a href='?page=<%=page+1%>'>下一页</a>
<a href='?page=<%=pagecount%>'>最末页</a>
  • 打赏
  • 举报
回复
数据库也是种很好的方法,我今天说的一堆糟糕方法有三种,数据库,xml和数组,其中真正的分页有两种,数据库和xml的静态型的,另外两种是js分页

分页的方法有不少关键是看自己如何抉择了
  • 打赏
  • 举报
回复
我的意思是说你建立一个xml文件就可以,可以用js的方式去显示,这个方法比较麻烦
Macon8800 2005-04-21
  • 打赏
  • 举报
回复
不明白 关注 等答案~
woshihuzi 2005-04-21
  • 打赏
  • 举报
回复
建立一个数据库吧,要不然,有了分页功能之后,每次翻页都要重新搜索一遍文件,岂不把服务器累死。
另外,建立数据库的好处在于,用SQL语句查询的时候,就可以非常方便地按照创建日期或者文件大小排序啦。
我给你一个分页程序的示例,才100行左右,巨简单,但是如何把你的搜索结果装到数据库中,我就不管了。~~
=============================================================================
<%@ Language=VBScript %>
<% Option Explicit %>
<% 'access-page2.asp %>
<html>
<head><title>分页技术</title></head>
<%
const MaxPerPage=3 ' 设置常量,控制每页显示多少条记录
dim CurrentPage ' 从参数中获取当前页序号
If trim(Request("Page"))="" then ' 参数为空,把变量CurrentPage置为1
CurrentPage= 1
ElseIf not(IsNumeric(trim(Request("Page")))) then ' 参数不是数值,把变量CurrentPage置为1
CurrentPage = 1
ElseIf CLng(trim(Request("Page")))<1 then ' 参数转换为整数值后,如果小于1,就把变量CurrentPage置为1
CurrentPage = 1
Else
CurrentPage = CLng(trim(Request("Page"))) ' 转换参数为整数值,并赋值给变量CurrentPage
End If
%>

<body bgcolor=Thistle>
<P align=center><FONT face=方正舒体><FONT size=5><FONT color="0000ff">
<STRONG>简单的分页技术</STRONG></FONT></FONT></FONT></P>

<% ' 获取所有记录
dim conn,sql,rs
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq=" &_
server.mappath("test.mdb")
sql = "SELECT * FROM friends"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize=MaxPerPage ' 设置每页最多显示的记录数量
if rs.PageCount>0 then ' 设置当前页
If CurrentPage>rs.PageCount then ' 使获取的页参数CurrentPage小于等于rs.PageCount
CurrentPage = rs.PageCount
end if
rs.absolutepage = CurrentPage ' 根据CurrentPage的值设置记录集的当前页
end if

if rs.eof then
response.write "<p align='center'> 数据库中没有记录!</p>"
else
' 首先输出记录总数、每页记录数、总页数、当前页序号
' 可以直接写成HTML代码,也可以用response.write输出,这里采用前者
%>

<P><center><hr width="70%">
共 <FONT color="ff0000"><%=rs.recordcount%></FONT> 条记录  
每页 <FONT color="ff0000"><%=MaxPerPage%></FONT> 条  
共有 <FONT color="ff0000"><%=rs.PageCount%></FONT> 页  
当前第 <FONT color="ff0000"><%=CurrentPage%></FONT> 页
<hr width="70%">
</P>

<% ' 下面开始输出当前页的所有记录

' 首先输出表头,这里是自动取出表的各个字段名称
dim howmanyfields,i,j
howmanyfields=rs.Fields.Count-1 '获取当前表的字段个数
response.write "<TABLE border=1 align=center>"
response.write "<tr>"
for i= 0 to howmanyfields
response.write "<TD><B>" & rs(i).name & "</B></TD>"
next

' 然后根据当前页面序号和页面大小输出范围内的每一条记录
i=0
do while not rs.eof and i<maxperpage
response.write "<tr align=middle>"
for j=0 to howmanyfields
response.write "<td>" & rs(j) & " </td>"
next
response.write "</tr>"
i=i+1
rs.movenext
loop
response.write "</TABLE>"
%>

<P><center><hr width="70%">
<%
if CurrentPage>1 then
%>
[<b><a href='access-page2.asp?page=1'>首页</a></b>]
[<b><a href='access-page2.asp?page=<%=cstr(CurrentPage-1)%>'>上一页</a></b>]
<%
else
%>
[首页] [上一页]
<%
end if

if CurrentPage<rs.PageCount then
%>
[<b><a href='access-page2.asp?page=<%=cstr(CurrentPage+1)%>'>下一页</a></b>]
[<b><a href='access-page2.asp?page=<%=cstr(rs.PageCount)%>'>尾页</a></b>]
<%
else
%>
[下一页] [尾页]
<%
end if
%>
</center>
<hr width="70%">
</P>

<% ' 关闭数据库连接和记录集
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

</body>
</html>
Tomato77 2005-04-21
  • 打赏
  • 举报
回复
另外,请问怎样确定文件的排序? 例如按文件创建日期或文件的大小排序。

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧