频道直达 - 学院 - 下载 - 交易 - 截图 - 特效 - 字库 - 手册 - 排名-工具 - 繁體
设为首页
加入收藏
联系我们
建站搜索: 虚拟主机  域名注册   常用广告代码      用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发 -> ASP -> 文章内容
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 通过google 赶快来赚..
· [图文] 头像-qq头像(..
· 要10G免费网络硬盘的..
· 注册码大全三
· 注册码大全十
· [图文] 梦幻背景图片..
· [图文] 卡通动物图片..
相关文章
· 域名突破注册方式 全球首..
· Fireworks打造极酷手枪
· Global.asa 参考(五) - ..
· 桔子数码照片创意教程
· 亲密接触ASP.Net(16)&am..;
· 用 PHP 实现的简单线性回..
· ASP出错集成处理
· ASP 编程中 15 个非常有..
· 人性和互联网
· 一分钟攻破ADSL 盗遍宽带..
用ASP构建你的网站新闻发布(二)
作者:佚名  来源:转载  发布时间:2005-7-18 16:41:30  发布人:acx

减小字体 增大字体

(二)添加和管理每天的新闻内容
    当进行了新闻提交后,则交由一个名为addnew.asp的asp程序来对新闻内容进行处理,以便分类和保存,为了显示清析,我们每提交一条新闻,下面的那个新闻内容库就重新读入,以便可以查看新闻是否能成功加入都数据库中,也可以放便地删除新闻内容。 
    现在看看addnew.asp是如何完成程序处理的。
  
  <% @language="vbscript" %>
  <%
  response.buffer=true
  Response.Expires=0
  
  ''保存数据
  session("title")=request.form("title")
  session("comment")=request.form("comment")
  session("pic")=request.form("pic")
  session("class_name")=request.form("class_name")
  session("head")=request.form("head")
  
  ''判断传过来的参数符不符合要求
  if request.form("title")="" then
  response.redirect "delete.asp"
  end if
  
  if request.form("comment")="" then
  response.redirect "delete.asp"
  end if
  
  if request.form("class_name")="" then
  response.redirect "delete.asp"
  end if
  
  
  select case request.form("class_name")
  
  case "市场风云"
  class=1
  case "IT新闻"
  class=2
  case "广州市场"
  class=3
  case "保 留"
  class=4
  case "保 留"
  class=4
  
  end select
  
  
  ''连接数据库
  %>
  <!--#include Virtual="/news/data/data.inc"-->
  <%
  
  Set rs = Server.CreateObject("ADODB.Recordset")
  sql="select * from data order by news_id ASC"
  rs.open sql,conn,3,2
  
  ''查找编号
  if rs.bof then
  reco=0
  else
  rs.movelast
  reco=Clng(rs("news_id"))+1
  end if
  
  rs.addnew
  rs("news_id")=reco
  
  if request.form("head")="YES" then
  rs("news_head")=-1
  end if
  
  rs("news_class")=class
  rs("news_class_name")=request.form("class_name")
  if request.form("pic")<>"" then
  rs("news_pic")=request.form("pic")
  rs("news_title")=request.form("title")&"(图文)"
  else
  rs("news_title")=request.form("title")
  end if
  
  
  
  if request.form("head")="YES" then
  rs("news_head")=-1
  end if
  
  tmpmess=request.form("comment")
  tmpmess=replace(tmpmess,chr(10),"  <br>")
  tmpmess=replace(tmpmess,"<","《")
  tmpmess=replace(tmpmess,">","》")
  tmpmess=replace(tmpmess,"《br》","<br>")
  rs("news_comment")=tmpmess
  rs("news_year")=year(Date)
  rs("news_month")=month(Date)
  rs("news_day")=day(Date)
  if Instr(Time,"下午")>0 then
  tmp=left(right(Time,8),2)+12
  rs("news_time")=tmp&right(Time,6)
  else
  rs("news_time")=tmp&right(Time,8)
  end if
  
  rs("news_delete")=0
  rs.update
  rs.close
  
  response.redirect "delete.asp"
  %>
  
  
    程序中首先判断了提交的新闻是否合符条件,比如新闻标题是不能为空的,而换行符也得转换为html语句的br,否则不能正常地显示出新闻的格式,而这里采用了一个包含文件data.inc,它的用处主要是用于连接不同的数据库,所以asp程序都通过包含这个文件来指定数据源,那么当更改使用别的数据库时,只需要更改这个文件,就能方便地实现来不同数据库间的切换,是不是十分方便呢?
    以下的data.inc文件的内容。
  <%
  Set conn = Server.CreateObject("ADODB.Connection")
  DBPath = Server.MapPath("/")&"/news/data/data.mdb"
  conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
  %>
  
  
    还有需要注意一下的是NT和windows 98的日期时间函数所返回的值是不同的,win98是以24小时来计算的,而NT Server则使用12小时,另外加上“上午”和“下午”来表示,因此需要作出少许的更该处理。
  
    程序处理完毕后,重新导向delete.asp这个asp文件,用以刷新新闻数据库内的显示,那么每提交一条新闻资料,我们马上可以看见执行的结果是否成功了。
  以下是delete.asp的文件内容。
  <% @language="vbscript" %>
  <%
  response.buffer=true
  Response.Expires=0
  
  %>
  <!--#include Virtual="/news/data/data.inc"-->
  <%
  
  Set rs = Server.CreateObject("ADODB.Recordset")
  sql="select * from data order by news_class ASC,news_id Desc"
  ''rs.PageSize=100
  rs.open sql,conn,3,2
  
  
  %>
  <html>
  
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title>新闻数据库中所存的资料</title>
  <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
  <style TYPE="text/css">
  <!--
  .lh22px {font-size:12px;line-height:22px;font-family:宋体}
  a { text-decoration: none}
  body {line-height:18px;font-size:9pt;font-family:宋体}
  td {line-height:18px;font-size:9pt;font-family:宋体}
  a:hover {color:#FF0000;text-decoration:none}
  -->
  </style>
  <meta name="Microsoft Border" content="none">
  </head>
  
  <body>
  
  <form method="POST" action="delete.asp">
  <table border="0" width="750" cellpadding="0">
  <tr>
  <td width="750" bgcolor="#EBEBEB" colspan="2"><div align="center"><center><p><font
  size="3"><strong>新闻数据库中所存的资料</strong></font></td>
  </tr>
  <%
  do while not rs.eof
  %>
  <tr align="center">
  <td width="112" bgcolor="#EBEBEB">是否删除:<%if rs("news_delete")=-1 then%>
  <input type="checkbox" name="<%=rs("news_id")%>"
  value="ON">
  <%else%>
  <input type="checkbox" name="<%=rs("news_id")%>"
  value="OFF">
  <%end if%>
  </td>
  <td width="638" bgcolor="#FAFAFA" align="left"><%if rs("news_class")=1 then%>
  <font color=red>市场风云</font>
  <%end if%>
  <%if rs("news_class")=2 then%>
  <font color=red>IT新闻</font>
  <%end if%>
  <%if rs("news_class")=3 then%>
  <font color=red>广州市场</font>
  <%end if%>
  <%if rs("news_class")=4 then%>
  <font color=red>保 留</font>
  <%end if%>
  <%if rs("news_class")=5 then%>
  <font color=red>保 留</font>
  <%end if%>
  <%=rs("news_title")%></td>
  </tr>
  <%
  rs.movenext
  loop
  %>
  <tr align="center">
  <td width="100%" colspan="2" bgcolor="#EBEBEB"><center><p><input
  type="submit" value="提 交" name="B1">      <input type="reset"
  value="清 除" name="B2"></td>
  </tr>
  </table>
  </form>
  </body>
  </html>
  <%
  
  if Request.ServerVariables("REQUEST_METHOD")="POST" then
  
  if not rs.bof then
  rs.movefirst
  end if
  do while not rs.eof
  n=trim(cstr(rs("news_id")))
  if request.form(n)="OFF" then
  rs.delete
  rs.update
  end if
  rs.movenext
  loop
  response.redirect "delete.asp"
  
  rs.close
  end if
  response.flush
  %>
    delete.asp也是一个构成webadmin.htm的管理页面的asp文件,它负责新闻数据库的标题显示,以便让您知道现在库用有些什么新闻。同时可以通过它来删除新闻记录,那么我们在使用新闻的主页里反应出来的结果就是动态的了,新闻可以在线添加和删除。令外一个附加的asp程序
  set_diap.asp是用于控制每一类新闻在主页上显示的数目的,它主要使用application对象来设定。
  
  <% @language="vbscript" %>
  <%
  response.buffer=true
  Response.Expires=0
  
  application("disp_1")=request.form("disp_1")
  application("disp_2")=request.form("disp_2")
  application("disp_3")=request.form("disp_3")
  application("disp_4")=request.form("disp_4")
  application("disp_5")=request.form("disp_5")
  
  
  response.redirect "delete.asp"
  %>
  
    完成了上面的程序,我们的新闻发布系统就可以在线添加和删除,设置显示等的功能来,需要加上搜寻功能,也可以在这个基础上加上。下一节我们来分析,如何;令新闻代码嵌入不同的网页,实现真正的在线新闻功能。 
   
  
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
免责申明:中国建站之家(www.jz123.cn)上的所有提供下载的软件和资源
均来源于网络,为软件或程序作者提供和网友推荐收集整理而来,仅供学习
和研究使用。如有侵犯你的版权,请立即联系我们,本站将在3个工作日内删除。
粤ICP备05092265号