用文本+ASP打造新闻发布系统( 3)新闻列表显示
<%
dim myfso,myread
myfso=createobject(\"scripting.filesystemobject\")
myread=myfso.opentextfile(server.mappath(\"./_list.asp\"),1,0)
myread.atendofstream then
Response.Write \"目前没有添加新闻\"
Response.End
dim mytext,list.gif' />
mytext=myread.readall
list.gif' />=split(mytext,\"|\") \'#######把所有记录分割成个a
dim recordcount,pagecount, pagesize, pagenum
recordcount=ubound(list.gif' />)\'############记录条数
pagesize=2
pagecount=recordcount/pagesize\'#######取得页面数
instr(1,pagecount,\".\")=null or instr(1,pagecount,\".\")=0 then
pagenum=pagecount
pagenum=(pagecount)+1
end
dim topage
topage=c(Request.QueryString (\"topage\"))\'########取得要显示页面
topage<=0 then
topage=1
end
topage>pagenum then
topage=pagenum
end
dim i,j,n
b=list.gif' />
for i=0 to recordcount-1 \'########把每条记录组成个
j=split(list.gif' />(i),\",\")
ubound(j)=6 then
b(i)=\"<SPAN style=\'COLOR: #ffbd00; FONT-SIZE: 7px\'><li></SPAN><span style=\'font-size:10pt\'><a href=\'s_view.asp?id=\" & j(0) & \"\' target=blank>\" & j(1) & \"(图)</a> 点击:\" & j(4)&\"次 最后发布时间:\"&j(5)&\"</span>\"
b(i)=\"<SPAN style=\'COLOR: #ffbd00; FONT-SIZE: 7px\'><li></SPAN><span style=\'font-size:10pt\'><a href=\'s_view.asp?id=\" & j(0) & \"\' target=blank>\" & j(1) & \"</a> 点击:\" & j(4)&\"次 最后发布时间:\"&j(5)&\"</span>\"
end
next
\'########把记录反排序存储在新实现按时间反排序
dim c(100)
n=0
for i=recordcount to 0 step -1
c(n)=b(i)
n=n+1
next
dim currentrecord
currentrecord=pagesize*(topage-1)+1 \'#########显示每页
for k=1 to pagesize
len(c(currentrecord))=0 then
exit for
end
Response.Write c(currentrecord)&\"<br>\"
currentrecord=currentrecord+1
next
Response.Write \"<body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0>\"
for m=1 to pagenum
response.write \"<span style=font-size:10pt><a href=s_list.asp?topage=\"&m&\">\"&m&\"</a></span> \"
next
end
%>
<!--# file=\"s_session.asp\"-->
<%
dim id
id=Request.QueryString (\"id\")
dim myfso
myfso=createobject(\"scripting.filesystemobject\")
myfso.FileExists(server.mappath(\"./s_content/\"&id&\".txt\"))then
myfso.DeleteFile (server.mappath(\"./s_content/\"&id&\".txt\"))\'#############删除新闻内容
end
dim mytext2,myread2
myread2=myfso.opentextfile(server.mappath(\"./_list.asp\"),1,0)
myread2.atendofstream then
Response.Write \"没有新闻内容\"
myread2.close
Response.End
end
mytext2=myread2.readall
myread2.close
dim list.gif' />,i,h,count,sf,title
list.gif' />=split(mytext2,\"|\") \'#########读取记录并以#分割成list.gif' />
count=ubound(list.gif' />)
for i=0 to count \'###########根据ID找到该新闻实现删除功能
sf=split(list.gif' />(i),\",\")
right(sf(0),7)=right(id,7) then
dim thisid
thisid=i
\'#######为6介绍说明上传了图片,删除新闻图片和该列表记录
ubound(sf)=6 then
myfso.deletefile(server.MapPath (\"./images/\"&sf(6)))
end
exit for
end
next
dim mytext,mappath
mappath=server.mappath(\"./\")
mytext=myfso.createtextfile(mappath&\"_list.asp\",-1,0)
for i=0 to thisid-1\'##########把所有数据重新写入文件
mytext.write list.gif' />(i)&\"|\"
next
for i=thisid+1 to ubound(list.gif' />)
i=ubound(list.gif' />)then
mytext.write list.gif' />(i)
exit for
mytext.write list.gif' />(i)&\"|\"
end
next
mytext.close
%>
<script language=\"javascript\">
alert(\"删除成功\");
location.href =(\"s_admin1.asp\");
</script>
---------------
s_view.asp
<%Response.Expires=0
dim myid,myfso,myread,mytext1
myid=request.query(\"id\")
len(myid)=0 then
Response.Write \"没有该新闻\"
Response.End
end
myfso=createobject(\"scripting.filesystemobject\")
myread=myfso.opentextfile(server.mappath(\"./s_content/\"&myid&\".txt\"),1,0)
myread.atendofstream then
Response.Write \"没有新闻内容\"
Response.End
mytext1=myread.readall\'#######打开对应新闻内容文件,并读取用变量存储
function htmlencode2(str)\'###########处理
dim result
dim l
l=len(str)
result=\"\"
dim i
for i = 1 to l
select mid(str,i,1)
chr(34)
result=result+\"\"\"\"
\"&\"
result=result+\"&\"
chr(13)
result=result+\"<br>\"
\" \"
result=result+\" \"
chr(9)
result=result+\" \"
chr(32)
result=result+\" \"
i+1<=l and i-1>0 then
mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9)then
result=result+\" \"
result=result+\" \"
end
result=result+\" \"
end
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
myread.close
end
dim mytext2,myread2
myread2=myfso.opentextfile(server.mappath(\"./_list.asp\"),1,0)
myread2.atendofstream then
Response.Write \"没有新闻内容\"
Response.End
mytext2=myread2.readall
myread2.close
dim list.gif' />,i,h
list.gif' />=split(mytext2,\"|\") \'#########读取记录并以#分割成list.gif' />
dim count,sf,title,src
count=ubound(list.gif' />)
for i=0 to count \'###########根据ID找到该新闻并把文章点击次数加1
sf=split(list.gif' />(i),\",\")
right(sf(0),7)=right(myid,7) then
title=sf(1)
src=sf(3)
sf(4)=sf(4)+1
\'#######为6介绍说明上传了图片,存储为新
ubound(sf)=6 then
list.gif' />(i)=sf(0)&\",\"&sf(1)&\",\"&sf(2)&\",\"&sf(3)&\",\"&sf(4)&\",\"&sf(5)&\",\"&sf(6)
dim mypic
mypic=sf(6)
list.gif' />(i)=sf(0)&\",\"&sf(1)&\",\"&sf(2)&\",\"&sf(3)&\",\"&sf(4)&\",\"&sf(5)
end
\'##################
exit for
end
next
dim k,mytext,mappath
mappath=server.mappath(\"./\")
mytext=myfso.createtextfile(mappath&\"_list.asp\",-1,0)
for i=0 to ubound(list.gif' />)\' ##########把所有数据重新写入文件
i=ubound(list.gif' />) then
mytext.write list.gif' />(i)
mytext.write list.gif' />(i)&\"|\"
end
next
Response.Write \"<body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0>\"
Response.Write\"<div align=center style=font-size:13pt><strong>\"&title&\"</strong><span></div><br>\"
Response.Write \"<hr size=1>\"
len(mypic)<>0 then
Response.write \"<center><img src=\'./images/\"&mypic&\"\'></center>\"
end
Response.Write \"<span style=font-size:10pt>\"&htmlencode2(mytext1)&\"</span>\"
Response.Write \"<br><div align=right style=\'font-size:9pt\'>新闻来源:<font color=red>\"&src&\"</font></div>\"
%>
<OBJECT id=closes type=\"application/x-oleobject\" id=\"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11\">
<param name=\"Command\" value=\"Close\">
</object>
<center><input type=\"button\" value=\"关闭窗口\" _disibledevent=>
<% end %>
最新评论