?? category.asp
字號:
<!--#include File="ConnDB.asp"-->
<%
On Error Resume Next
Dim rs, sql
Set rs = Server.CreateObject("ADODB.RecordSet")
Dim curpage, curcate, strcate
'讀取新聞類別編號參數flag
If Request("flag") = "" Then
curcate = "1"
Else
curcate = Request("flag")
End If
%>
<html>
<head>
<title>新聞列表</title>
<meta HTTP-EQUIV="Content-cate" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<script language="JavaScript">
function newwin(url) {
var wth=window.screen.width;
var hth=window.screen.heigth;
var lefth,topth;
if(wth==1024)
{
hth=500;
lefth =147;
wth=550;
topth=44;
}
else if(wth==800)
{
hth=500;
lefth =35;
wth=500;
topth=10;
}
else
{
hth=500;
wth=500;
}
var oth="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left="+lefth+",top="+topth;
oth = oth+",width="+wth+",height="+hth ;
var newwin=window.open(url,"newwin",oth);
newwin.focus();
return false;
}
</script>
</head>
<body>
<%
'讀取頁碼參數page
If Request("Page")="" Then
curpage = 1
Else
curpage = CInt(Request("Page"))
End If
'設置SQL語句,按發表時間倒序讀取新聞信息
sql = "SELECT * FROM News WHERE CateId=" & CInt(curcate) & " ORDER BY Posttime DESC"
rs.Open sql, Conn, 1, 1
'錯誤處理
If err.number <> 0 Then
Response.Write "數據庫出錯"
Else
If rs.EOF Then
rs.close
Response.Write "沒有新聞"
Else
'獲得類別信息
Dim newsCate
Set newsCate = Server.CreateObject("ADODB.RecordSet")
'設置SQL語句,讀取新聞類別名稱
sqlcate = "SELECT CateName FROM Category WHERE CateId = " & CInt(curcate)
Set newsCate = Conn.Execute(sqlcate)
'顯示新聞類別名稱
If Not newsCate.EOF Then
cateTitle = newsCate("CateName")
End If
%>
<div align=center><strong><font color="blue" size="3"><%=cateTitle%></font></strong></div>
<%
dim i
'分頁顯示新聞列表
rs.PageSize = 20
'設置當前頁碼
rs.AbsolutePage = curpage
'畫表頭
Response.Write "<table width='100%' align=center cellspacing=1 cellpadding=2>"
Response.Write "<tr bgcolor=#ffffff><td width='100%' colspan=3 height=20><center><font color=#000000 size=2>" + strcate + "</font></td></tr>"
Response.Write "<tr bgcolor=#ceceff><td width='65%' height=15> == 新 聞 標 題 ==</td><td width='30%' height=15><center>日期</td><td width='5%' height=15><center>點擊</td></tr>"
'使用循環語句,讀取并顯示新聞列表
For i = 1 to rs.PageSize
Dim ndate
'顯示新聞標題鏈接
Response.Write "<tr bgcolor=#ffffff><td><font color=#336699> </font><a onclick='return newwin(this.href)' href=newsview.asp?id=" + cstr(rs("id")) + ">" + rs("Title") + "</a>"
'處理(附圖)標記
If rs("Attpic") = true Then
Response.Write "(附圖)"
End If
'如果是最近3天發表的新聞,則顯示new圖標
ndate=DateAdd("d",-3,date())
If DateDiff("d", rs("Posttime"), ndate+time()) <=0 then
Response.Write"<img SRC='pic/new.gif' ALT='最新的新聞!' border=0></td>"
End If
'顯示閱讀數量
Response.Write "</td><td><center>" + formatdatetime(rs("Posttime")) + "</td><td><center>" + cstr(rs("ReadCount")) + "</td></tr>"
'將指針移到下一條記錄
rs.MoveNext
'如果到達記錄集結尾,則跳出循環
If rs.EOF Then
i = i + 1
Exit For
End If
Next
Response.Write "<tr bgcolor=#ffffff><td width='100%' height=15 colspan=3><center>"
'下面顯示頁碼信息
Response.Write "第" + cstr(curpage) + "頁/總" + cstr(rs.pagecount) + "頁 "
Response.Write "本頁" + cstr(i-1) + "條/總" + cstr(rs.recordcount) + "條 "
If curpage = 1 Then
Response.Write "首頁 上一頁 "
Else
Response.Write "<a href='category.asp?page=1&cate=" + cstr(curcate) + "'>首頁</a> <a href='category.asp?page=" + cstr(curpage-1) + "&cate=" + cstr(curcate) + "'>上一頁</a> "
End If
If curpage = rs.PageCount then
Response.Write "下一頁 尾頁"
Else
Response.Write "<a href='category.asp?page=" + cstr(curpage+1) + "&cate=" + cstr(curcate) + "'>下一頁</a> <a href='category.asp?page=" + cstr(rs.pagecount) + "&cate=" + cstr(curcate) + "'>尾頁</a>"
End If
Response.Write "</td></tr></tr></td></table>"
rs.close
End If
End If
Set rs = Nothing
%>
<br>
<p align=center><a href="default.asp">[返回新聞中心]</a>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -