最新看到论坛里有朋友提到asp转html时文章列表遇到一些问题,
所以想写个例子出来看能不能对某些人有帮助:
数据表名是:news
这里我只是做个例子,所以表相对简单,news表只有二个字段:id,topic
id是关键字段,topic是标题
下面开始:
<!-- #include file="conn.asp" -->
<%
if request("action")="news" then
call send_news()
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>发布列表</title>
</head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF">
<form action="?action=news" method="post" name="form1">
<tr bgcolor="#f4f3f0"> <input name="types" type="hidden" value="news">
<td height="50" align="center"><input name="Submit" type="submit" value="提交生成文件列表"></td>
</tr>
</form>
</table>
</body>
</html>
<%
sub send_news()
if request.Form("types")="news" then
dim file_name,temp1,nname,topic,rssum,nummer,thepages,j,nums
nummer=10 '每页显示的记录数
nums=nummer
sql="select count(id) from news"
set rs=server.CreateObject("adodb.Recordset")
rs.open sql,conn,1,1
rssum=rs(0)
if rssum mod nummer > 0 then
thepages=rssum\nummer+1
else
thepages=rssum\nummer
end if
'thepages计算出总的页数
'下面从第一页到最后一页行成文件
for i=1 to thepages
'有必要的时候加上这句 nums=nummer
'下面是页面的内容
temp1="<html><head><title>"
temp1=temp1&vbcrlf&"第"&i&"页</title></head><body>"
sql="select * from news"
set rs1=server.CreateObject("adodb.Recordset")
rs1.open sql,conn,1,1
rs1.move (i-1)*nummer
if int(i*nummer)>int(rssum) then nums=nummer-(i*nummer-rssum)
for j=1 to nums
temp1=temp1&vbcrlf&"<div>· <a href=''>"&rs1("topic")&"</a></div>"
rs1.movenext
next
'分页开始
temp1=temp1&vbcrlf&"<div>当前共有"&rssum&"条信息, 页次:"&i&"/"&thepages&" "
temp1=temp1&vbcrlf&zxt_page(nummer,thepages,i,3,"#ff0000")
temp1=temp1&vbcrlf&"</div>"
'分页结束
temp1=temp1&vbcrlf&"</body></html>"
'页面内容结束,内容都在temp1变量里
'得出文件名并赋值给file_name
if thepages=1 then
file_name="list.html"
else
if i=1 then
file_name="list.html"
else
file_name="lists"&i&".html"
end if
end if
'开始生成html文件
call create_file(file_name,temp1)
next
Response.Write("<script>alert(""发布成功"");location.href=""send_html.asp"";</script>")
Response.End()
end if
end sub
''============================================================
'建文件函数,file_name文件名,filetype是文件的内容
'=============================================================
sub create_file(file_name,filetype)
dim filetemp,fileos,filepath
dim fso_sys_var
fso_sys_var="script"&"ing.file"&"sys"&"tem"&"object"
set fileos=createobject(fso_sys_var)
filepath=server.mappath(file_name)
set filetemp=fileos.createtextfile(filepath,true)
filetemp.writeline( filetype )
filetemp.close
set filetemp=nothing
set fileos=nothing
end sub
''============================================================
'分页函数,maxpage每页显示的页数,thepages总页数,viewpage当前页数
'pp翻页数,font_color当前页的颜色
'=============================================================
function zxt_page(maxpage,thepages,viewpage,pp,font_color)
if int(thepages)=0 then
zxt_page="<font color=" & font_color & ">[1]</font>"
exit function
end if
dim pn,pi,page_num,ppp,pl,pr
pi=1
ppp=pp\2
if pp mod 2 = 0 then ppp=ppp-1
pl=viewpage-ppp
pr=pl+pp-1
if pl<1 then
pr=pr-pl+1
pl=1
if pr>thepages then pr=thepages
end if
if pr>int(thepages) then
pl=pl+thepages-pr
pr=thepages
if pl<1 then pl=1
end if
if pl>1 then
zxt_page=zxt_page&" <a href='list.html' title='第一页'>[|<]</a> "
if pl-1=1 then
zxt_page=zxt_page&" <a href='list.html' title='上一页'>[<]</a> "
else
zxt_page=zxt_page&" <a href='lists"&pl-1&".html' title='上一页'>[<]</a> "
end if
end if
for pi=pl to pr
if cint(viewpage)=cint(pi) then
zxt_page=zxt_page&" <font color=" & font_color & ">[" & pi & "]</font> "
else
if pi=1 then
zxt_page=zxt_page&" <a href='list.html' title='第 " & pi & " 页' clases=0>[" & pi & "]</a> "
else
zxt_page=zxt_page&" <a href='lists"& pi &".html' title='第 " & pi & " 页' clases=0>[" & pi & "]</a> "
end if
end if
next
if pr<thepages then
zxt_page=zxt_page&" <a href='lists"&pi&".html' clases=0 title='后一页'>[>]</a> " & _
" <a href='lists"& thepages &".html' title='最后一页'>[>|]</a> "
end if
end function
%>
到这里结束
显示内容自己去扩展了,
这里只是写个例子。