a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

構(gòu)建你的網(wǎng)站新聞自動(dòng)發(fā)布系統(tǒng)之二

2019-11-18 22:45:03
字體:
供稿:網(wǎng)友
(二)添加和管理每天的新聞內(nèi)容
  當(dāng)進(jìn)行了新聞提交后,則交由一個(gè)名為addnew.asp的asp程序來對(duì)新聞內(nèi)容進(jìn)行處理,以便分類和保存,為了顯示清析,我們每提交一條新聞,下面的那個(gè)新聞內(nèi)容庫就重新讀入,以便可以查看新聞是否能成功加入都數(shù)據(jù)庫中,也可以放便地刪除新聞內(nèi)容。 
  現(xiàn)在看看addnew.asp是如何完成程序處理的。

《% @language="vbscript" %》
《%
response.buffer=true
Response.Expires=0

'保存數(shù)據(jù)
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")

'判斷傳過來的參數(shù)符不符合要求
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 "市場(chǎng)風(fēng)云"
class=1
case "IT新聞"
class=2
case "廣州市場(chǎng)"
class=3
case "保 留"
class=4
case "保 留"
class=4

end select


'連接數(shù)據(jù)庫
%》
《!--#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

'查找編號(hào)
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),"
")
tmpmess=replace(tmpmess,"《","《")
tmpmess=replace(tmpmess,"》","》")
tmpmess=replace(tmpmess,"
","
")
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"
%》


  程序中首先判斷了提交的新聞是否合符條件,比如新聞標(biāo)題是不能為空的,而換行符也得轉(zhuǎn)換為html語句的br,否則不能正常地顯示出新聞的格式,而這里采用了一個(gè)包含文件data.inc,它的用處主要是用于連接不同的數(shù)據(jù)庫,所以asp程序都通過包含這個(gè)文件來指定數(shù)據(jù)源,那么當(dāng)更改使用別的數(shù)據(jù)庫時(shí),只需要更改這個(gè)文件,就能方便地實(shí)現(xiàn)來不同數(shù)據(jù)庫間的切換,是不是十分方便呢?
  以下的data.inc文件的內(nèi)容。
《%
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的日期時(shí)間函數(shù)所返回的值是不同的,win98是以24小時(shí)來計(jì)算的,而NT Server則使用12小時(shí),另外加上“上午”和“下午”來表示,因此需要作出少許的更該處理。

  程序處理完畢后,重新導(dǎo)向delete.asp這個(gè)asp文件,用以刷新新聞數(shù)據(jù)庫內(nèi)的顯示,那么每提交一條新聞資料,我們馬上可以看見執(zhí)行的結(jié)果是否成功了。
以下是delete.asp的文件內(nèi)容。
《% @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》新聞數(shù)據(jù)庫中所存的資料《/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》新聞數(shù)據(jù)庫中所存的資料《/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》市場(chǎng)風(fēng)云《/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》廣州市場(chǎng)《/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也是一個(gè)構(gòu)成webadmin.htm的管理頁面的asp文件,它負(fù)責(zé)新聞數(shù)據(jù)庫的標(biāo)題顯示,以便讓您知道現(xiàn)在庫用有些什么新聞。同時(shí)可以通過它來刪除新聞?dòng)涗洠敲次覀冊(cè)谑褂眯侣劦闹黜摾锓磻?yīng)出來的結(jié)果就是動(dòng)態(tài)的了,新聞可以在線添加和刪除。令外一個(gè)附加的asp程序
set_diap.asp是用于控制每一類新聞在主頁上顯示的數(shù)目的,它主要使用application對(duì)象來設(shè)定。

《% @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"
%》

  完成了上面的程序,我們的新聞發(fā)布系統(tǒng)就可以在線添加和刪除,設(shè)置顯示等的功能來,需要加上搜尋功能,也可以在這個(gè)基礎(chǔ)上加上。下一節(jié)我們來分析,如何;令新聞代碼嵌入不同的網(wǎng)頁,實(shí)現(xiàn)真正的在線新聞功能。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青青草视频播放 | 成人午夜精品久久久久久久蜜臀 | 日本久久精品电影 | 久久这| 国产日韩高清在线 | 亚洲精品久久久久久久久久久 | 免费的日本网站 | 国产精品91色 | 欧美日韩国产一区二区三区不卡 | 亚洲精品久久久久久久久久久 | 亚洲成人在线视频观看 | 国产精品一区二区三区四区在线观看 | 中文字国产精久久无 | 欧美国产在线观看 | 日韩免费在线观看视频 | 成人小视频在线观看 | 美日韩一区二区三区 | 欧美激情在线播放 | 成人日韩精品 | 亚洲自拍偷拍av | 啪一啪免费视频 | 女bbwxxxx另类| 国产成人在线播放 | 欧美日韩一二 | 九九热最新视频 | 日韩国产免费观看 | 欧美黄视频在线观看 | 国产精品欧美一区二区 | 久在线视频 | 亚洲第一福利视频 | 日韩成人综合 | 日韩毛片在线免费观看 | 娇妻被3p高潮爽视频 | 国产日韩一区二区 | 中文字幕精品一区久久久久 | 精品日韩欧美一区二区在线播放 | 亚洲精品久久久蜜臀 | 久久久久久av | 日韩三级黄 | 黄色三及毛片 | 九九热在线免费观看 |