top
Loading...
構建你的網站新聞自動發布系統之一
更新每天新聞內容,對webmaster們來說是一件很頭痛的事,首先,收集了大量的新聞資料后,還必須制作大量的網頁,每天大大小小的國際新聞,國內新聞,IT新聞,可真夠你累的。最致命的一點,這些松散的新聞是管理不了的,不能查詢,不能在線動態刪改,新聞講求時效性,當你作好網頁然后上傳到服務器上的時侯,恐怕別人已早你一步,把新聞報導出來了。當真吃力不討好,針對現在我們的上網環境,在線發布新聞,動態生成新聞網頁,為新聞添加搜索,查找功能是必不可少的。
那么,使用ASP技術如何來實現動態的新聞發布系統呢?而新聞系統的做法大致上有兩種,一就是把錄入的新聞內容自動由程序直接生成html文件,比如按日期和新聞ID號來做htm文件的名稱,我們常常可以從一些大的新聞站看到這樣的處理。而另一種就是直接把新聞數據保存到數據庫里,當用戶閱讀新聞時。從數據庫中調出數據,動態生成頁面。
兩種處理有何差別?第一種的顯示速度和對服務器的負何來說,是最輕的。對于大流量的站點,速度就是生命,網站太慢了,有誰去瀏纜呢?后一種方法在處理上比教簡便。維護也方便,還有一種就是兩種雙結何,因為只有應用數據庫才能方便地處理查詢,從而把讀者引導至相應的新聞頁面,綜合上面的方法,可以說都是各有千秋,現在我們主要介紹使用數據庫的那種動態頁面方法。

從處理流程上來說,主要是提供一個管理新聞的頁面(可以添加和刪除每天的新聞,包括新聞圖片,標題等),然后在到調用新聞的顯示頁面處理。考濾到新聞需要插到不同風格的網頁中,所以不能使用一個固定格式的頁面來顯示新聞提要。應當把它們做成一個主頁的可插入部分,那么就可以在不同風格的頁面上調用新聞了。就如下面的script語句

《script language="JavaScript" src="http//xxx.com.cn/special/linux/lnews/autoup.asp"》
《/script》
最后還有一個閱讀新聞時的詳細內容頁面。總的來說,也就是一個可以完成在線新聞發布的程序主要由四大部分程序構成
addnew.asp(用于把新聞數據保存到數據庫中)delete.asp(用于處理刪除新聞)
autoup.asp(用于處理新聞的標題顯示,也就是插入主頁的部分)read.asp(動態生成新聞的詳細內容)
附助處理的部分有set_disp.asp(用于處理新聞在主頁的顯示數目等等)
當然,必不可少的就是一個新聞數據庫了。

(一)構建新聞數據庫
分析一下構成每條新聞的元素,主要由新聞標題,新聞內容,圖片地址,連接地址,新聞的發布時間組成。而在構建數據庫的時候。考慮到處理需要,必需加上新聞的ID號,以便識別。再者的話,可以加上點擊統計,以便了解讀者感性趣的內容。Access數據庫是一個非常適合于開發階段使用的過度時期數據庫,因此。我們構造如下的一個新聞數據庫(data.mdb)
表data
news_idlong新聞的編號
news_classtext新聞的類別
news_class_nametext新聞的類別名
news_titletext新聞的標題
news_headlogic是否首頁顯示
news_commentcomment新聞的內容
news_yeartext新聞的年份
news_monthtext新聞的月份
news_daytext新聞的內容
news_timetext更新時間
news_deletelogic刪除標志

按上述的要求建好這個表,當我們經過測試穩定后,就可以把新聞數據庫轉入SQL server里面
了。好了,接這下來的這步,我們一起來做一個新聞的管理頁面,為了布局和管理方便,我們采用
框架結構做出如下的面頁。Webadmin.htm框架的主文件。

《html》

《head》
《meta http-equiv="Content-Type" content="text/html; charset=gb2312"》
《title》新聞發布系統管理頁《/title》
《meta name="GENERATOR" content="Microsoft FrontPage 3.0"》
《/head》

《frameset framespacing="0" rows="*,14%"》
《frame name="main" target="footnotes" src="webadmin.asp" scrolling="auto"》
《frame name="footnotes" src="delete.asp" scrolling="auto"》
《noframes》
《body》
《p》This page uses frames, but your browser doesn't support them.《/p》
《/body》
《/noframes》
《/frameset》
《/html》


而面包含的文件是webadmin.asp這個文件。主要由它提供錄入新聞的每天更新界面,代碼如下。
《html》

《head》
《meta http-equiv="Content-Type" content="text/html; charset=gb2312"》
《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》
《base target="footnotes"》
《title》新聞發布系統管理頁《/title》
《/head》

《body topmargin="8" leftmargin="8"》

《p align="center"》《font face="楷體_GB2312" size="6" color="#FF0000"》《strong》新聞發布系統WEB管理頁《/strong》《/font》《/p》
《div align="center"》《center》

《table border="0" width="100%" cellspacing="0" cellpadding="0"》
《tr》
《td width="100%"》《form method="POST" action="addnew.asp"》
《table border="0" width="100%" height="126" cellpadding="0"》
《tr》
《td width="100%" height="9" colspan="2" bgcolor="#E7E7E7"》《div align="center"》《center》《p》《font
size="3"》《strong》添加每天新聞內容《/strong》《/font》《/td》
《/tr》
《tr align="center"》
《td width="15%" height="8" bgcolor="#E7E7E7"》《div align="left"》《p》新聞標題:(必須)《/td》
《td width="85%" height="8" bgcolor="#F9F9F9"》《div align="left"》《p》《input type="text"
name="title" size="73"》《/td》
《/tr》
《tr align="center"》
《td width="15%" height="34" bgcolor="#E7E7E7" valign="top"》《div align="left"》《p》新聞內容:(必須)《/td》
《td width="85%" height="34" bgcolor="#F9F9F9"》《div align="left"》《p》《textarea rows="13"
name="comment" cols="72"》《/textarea》《/td》
《/tr》
《tr align="center"》
《td width="15%" height="17" bgcolor="#E7E7E7"》《div align="left"》《p》圖片連接地址:《/td》
《td width="85%" height="17" bgcolor="#F9F9F9"》《div align="left"》《p》《input type="text"
name="pic" size="73"》《/td》
《/tr》
《tr align="center"》
《td width="15%" height="17" bgcolor="#E7E7E7"》《div align="left"》《p》新聞類型:(必須)《/td》
《td width="85%" height="17" bgcolor="#F9F9F9"》《div align="left"》《p》《select
name="class_name" size="1" value="《%=session("class_name")%》"》
《option value="市場風云"》市場風云《/option》
《option value="IT新聞"》IT新聞《/option》
《option value="廣州市場"》廣州市場《/option》
《option value="保留"》保留《/option》
《option value="保留"》保留《/option》
《/select》《/td》
《/tr》
《tr align="center"》
《td width="15%" height="17" bgcolor="#E7E7E7"》《div align="left"》《p》是否首頁:《/td》
《td width="85%" height="17" bgcolor="#F9F9F9"》《div align="left"》《p》《input type="checkbox"
name="head" value="YES"》《/td》
《/tr》
《tr align="center"》
《td width="100%" height="16" colspan="2" bgcolor="#E7E7E7"》《div align="center"》《center》《p》《input
type="submit" value="提交" name="B1"》《input type="reset"
value="清除" name="B2"》《/td》
《/tr》
《/table》
《/form》
《/td》
《/tr》
《/table》
《/center》《/div》《div align="center"》《center》

《table border="0" width="750" cellpadding="0"》
《tr》
《td width="740"》《/td》
《/tr》
《tr》
《td width="740"》《form method="POST" action="set_disp.asp"》
《table border="0" width="100%" cellpadding="0"》
《tr》
《td width="100%" bgcolor="#E7E7E7" colspan="5"》《div align="center"》《center》《p》首頁新聞顯示條數設置《/td》
《/tr》
《tr》
《td width="20%"》《div align="center"》《center》《p》廣州市場《/td》
《td width="20%"》《div align="center"》《center》《p》市場風云《/td》
《td width="20%"》《div align="center"》《center》《p》IT新聞《/td》
《td width="20%"》《div align="center"》《center》《p》保留《/td》
《td width="20%"》《div align="center"》《center》《p》保留《/td》
《/tr》
《tr》
《td width="20%"》《div align="center"》《center》《p》《input type="text" name="disp_1" size="10"
value="《%=application("disp_1")%》"》《/td》
《td width="20%"》《div align="center"》《center》《p》《input type="text" name="disp_2" size="10"
value="《%=application("disp_2")%》"》《/td》
《td width="20%"》《div align="center"》《center》《p》《input type="text" name="disp_3" size="10"
value="《%=application("disp_3")%》"》《/td》
《td width="20%"》《div align="center"》《center》《p》《input type="text" name="disp_4" size="10"
value="《%=application("disp_4")%》"》《/td》
《td width="20%"》《div align="center"》《center》《p》《input type="text" name="disp_5" size="10"
value="《%=application("disp_5")%》"》《/td》
《/tr》
《tr》
《td width="100%" bgcolor="#E7E7E7" colspan="5"》《div align="center"》《center》《p》《input
type="submit" value="提交" name="B1"》《input type="reset"
value="清除" name="B2"》《/td》
《/tr》
《/table》
《/form》
《/td》
《/tr》
《tr》
《td width="740"》《/td》
《/tr》
《tr》
《td width="740"》《font color="#FF0000"》附注《/font》新聞標題:即為顯示在主頁中的連接標題,因此不可省略。《/td》
《/tr》
《tr》
《td width="740"》新聞內容:為點擊標題連接后窗口所打開顯示的新聞內容,也不允許省略。《/td》
《/tr》
《tr》
《td width="740"》新聞圖片:新聞包含圖片,請把圖片地址連接復制在此,以便顯示圖片《/td》
《/tr》
《tr》
《td width="740"》新聞類型:選擇新聞在不同欄目中顯示的位置《/td》
《/tr》
《tr》
《td width="740"》是否首頁:如首頁的綜合新聞包需含圖片,請復選此項《/td》
《/tr》
《tr》
《td width="740"》《p align="center"》《a href="index.asp" target="_parent"》返回新聞首頁《/a》《/td》
《/tr》
《/table》
《/center》《/div》
《/body》
《/html》

好了,下節“添加每天的新聞內容”將為您介紹如何對新聞數據進行處理,請先按步驟建立好上面的編程環境。

北斗有巢氏 有巢氏北斗