線上 ASP進階之文章線上管理更新--首頁面及搜尋篇
作者:沙灘小子
經過了文章的添加、儲存、顯示,那麼現在應該來談談關於管理程式的顯示首頁面,也就是顯示所有文章的標題串連,以方便瀏覽者尋找文章,其應該具有的功能有:顯示所有文章的標題串連,加入日期,瀏覽次數等資訊,另外還必須提供分頁功能,要不然這麼多的文章標題在一個頁面都顯示出來,那將非常的費時且不便瀏覽,另外由於本程式在這裡結合了文章分欄目搜尋的功能,所以在這裡也將一起介紹了。
下面就為大家詳細的介紹首頁面index.asp的這些功能的實現過程以及其具體功用:
"建立資料庫連接
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP專題欄目</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" type="text/css" href="style.css">
<script language="javascript">
function popwin2(path)
{ window.open(path,"","height=450,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
</head>
<%
"定義每頁最大文章標題顯示量MaxPerPage,你可以自己修改這裡的數字來達到你的最佳顯示效果
const MaxPerPage=18
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
"假如返回的頁面資訊是空的,也就是如果你直接輸入index.asp,那麼就用這裡定義的頁數第一頁
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
dim sql
dim rs
dim rstype
dim typesql
dim typeid,typename
"如果返回的欄目資訊為空白,那麼就用這裡定義的欄目,這裡指定的是第三個欄目
if not isEmpty(request("typeid")) then
typeid=request("typeid")
else
typeid=3
end if
"通過返回的欄目typeid號,開啟資料庫顯示指定的欄目,並把其值交給typename
set rstype=server.createobject("adodb.recordset")
typesql="select * from type where typeID="&cstr(typeid)
rstype.open typesql,conn,1,1
typename=rstype("type")
rstype.close
%>
<body>
<div align="center"><center>
<table border="0" width="95%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" style="border-left: thin dotted rgb(0,128,0); border-right: thin dotted rgb(0,128,0)"><p align="center"><br>
"顯示欄目資訊,當你點擊了任何一個欄目,在typename的位置都會顯示相關資訊,這裡沒有採用欄目的自動顯示方式是考慮了頁面的顯示效果,而採用手工添加的模式,要想採用自動模式,就自己寫吧:)相信你學習到現在,不會連這個都編不出來吧!
動網ASP技巧專題>><font color="#FF0000"><%response.write ""&typename&""%></font><br>
<a href="index.asp?typeid=1">ASP FAQ</a>|<a href="index.asp?typeid=2">ASP組件</a> |<a href="index.asp?typeid=3">ASP文摘</a>|<a href="index.asp?typeid=4">ASP執行個體</a>|<a href="index.asp?typeid=5">ASP安全</a> </p>
<div align="center">
"開啟指定的記錄集article並按照文章的加入日期排序,在這裡開啟有兩個條件,一個是利用like來查詢資料庫並顯示相關文章標題,還有就是通過返回的typeid顯示指定欄目的文章
<%
sql="select * from article where title like '%"&request("txtitle")&"%' and typeid="+cstr(typeid)+" order by date desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
"如果查詢資料庫的結果指向記錄集的開始或者結尾,表示資料庫中沒有任何相關文章
if rs.eof and rs.bof then
response.write "<p align='center'>沒有或沒有找到任何文章</p>"
else
"如果資料庫內有內容,則取得資料庫內文章數目
totalPut=rs.recordcount
"假如頁面參數currentpage小於1,則指定為1
if currentpage<1 then
currentpage=1
end if
"利用文章總數和每頁最大文章數算得分頁的頁數
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
"如果分頁的頁數為1或者頁面數減1乘與頁面最大文章數小於文章總數,則用已經做好的function showpage在showContent子程式也就是顯示文章標題部分的上面和下面顯示分頁程式
if currentPage=1 then
showpage totalput,MaxPerPage,"index.asp"
showContent
showpage totalput,MaxPerPage,"index.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
"定義書籤
dim bookmark
bookmark=rs.bookmark
showpage totalput,MaxPerPage,"index.asp"