⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 category.asp

📁 asp+sql基于WEB新闻发布系统 代码加论文
💻 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>&nbsp;==&nbsp;新&nbsp;闻&nbsp;标&nbsp;题&nbsp;==</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>&nbsp;&nbsp;</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 + -