searchshow.asp
来自「《动态网页设计基础教程》,胡杰,科学出版社」· ASP 代码 · 共 147 行
ASP
147 行
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Option Explicit
Response.Expires=0
%>
<!--#include file=adovbs.inc -->
<!--#include file=connection.asp -->
<%
Dim RecordPerPage,absPageNUm,TotalPages,absRecordNUm,rsTest,StrSQL
'absPageNum-当前页数,TotalPages-总页数,absRecordNum-当前页中某一条记录的序号
RecordPerPage=4 '每页显示的记录数
absPageNum=CInt(Request.Form("PressPageNum"))
'若返回的是"上一页",则页数减一,若是"下一页",则页数加一
If Request.Form("Submit")="上一页" Then
absPageNum=absPageNum-1
ElseIf Request.Form("Submit")="下一页" Then
absPageNum=absPageNum+1
End If
If Session("Checkbox")="on" Then
If Session("Credit")=0 And Session("Teacherno")<>"所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Teacherno='"&Session("Teacherno")&"' And Maximumnum>Currentnum"
ElseIf Session("Credit")<>0 And Session("Teacherno")="所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Credit="&Session("Credit")&" And Maximumnum>Currentnum"
ElseIf Session("Credit")=0 And Session("Teacherno")="所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Maximumnum>Currentnum"
Else
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Credit="&Session("Credit")&" And Teacherno='"&Session("Teacherno")&"' And Maximumnum>Currentnum"
End If
Else
If Session("Credit")=0 And Session("Teacherno")<>"所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Teacherno='"&Session("Teacherno")&"' "
ElseIf Session("Credit")<>0 And Session("Teacherno")="所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Credit="&Session("Credit")&" "
ElseIf Session("Credit")=0 And Session("Teacherno")="所有教师" Then
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' "
Else
StrSQL="Select * From Course Where Name Like '%"&Session("Name")&"%' And Description Like '%"&Session("Description")&"%' And Credit="&Session("Credit")&" And Teacherno='"&Session("Teacherno")&"' "
End If
End If
Set rsTest=Server.CreateObject("ADODB.RecordSet")
rsTest.CacheSize=RecordPerPage '设置这个属性选项会提高性能
rsTest.Open StrSQL,Conn,adOpenStatic,adLockReadOnly,adCmdText
'设置RecordSet对象的每一页数据记录条数
If rsTest.RecordCount=0 Then
Response.Redirect "searcherror.asp"
End If
rsTest.PageSize=RecordPerPage
If absPageNum=0 Then
absPageNum=1
End If
If Not rsTest.EOF Then
rsTest.AbsolutePage=absPageNum
End If
TotalPages=rsTest.PageCount
%>
<Html>
<Head>
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<Title>浏览课程信息</Title>
</Head>
<Body>
<P> </P>
<Table width="99%" border="0">
<Tr>
<Td height="49">
<Div align="center"><Font color="#009900" size="7" face="华文新魏">课 程 信 息 一 览 表</Font></Div></Td>
</Tr>
<Tr>
<Td height="100">
<Table width="100%" height="90" border="1" bordercolor="#0000FF">
<Tr>
<Td width="8%" height="38">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">课程号</Font>
</Div>
</Td>
<Td width="27%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">课程名称</Font>
</Div>
</Td>
<Td width="7%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">学分</Font>
</Div>
</Td>
<Td width="9%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">最大选课人数</Font>
</Div>
</Td>
<Td width="9%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">目前选课人数</Font>
</Div>
</Td>
<Td width="8%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">教师号</Font>
</Div>
</Td>
<Td width="41%">
<Div align="center">
<Font color="#CC6600" size="4" face="华文隶书">课 程 描 述</Font>
</Div>
</Td>
</Tr>
<%
For absRecordNum=1 to rsTest.PageSize
Response.Write "<Tr valign=middle>"
'将每条记录的各个字段输出
Response.Write "<Td>"&rsTest("Courseno").Value&"</Td>"
Response.Write "<Td>"&rsTest("Name").Value&"</Td>"
Response.Write "<Td>"&rsTest("Credit").Value&"</Td>"
Response.Write "<Td>"&rsTest("Maximumnum").Value&"</Td>"
Response.Write "<Td>"&rsTest("Currentnum").Value&"</Td>"
Response.Write "<Td>"&rsTest("Teacherno").Value&"</Td>"
Response.Write "<Td>"&rsTest("Description").Value&"</Td>"
Response.Write "</Tr>"
rsTest.MoveNext
If rsTest.EOF Then
Exit For '若到记录尾,退出-如当最后一页数据不满页时。
End If
Next
Response.Write "</Table><Br>"
'关闭数据库和数据表
rsTest.Close
Conn.Close
Set rsTest=Nothing
Set Conn=Nothing
%>
<Form Action="<% =Request.ServerVariables("SCRIPT_NAME") %>" Method="Post">
<Input Type="Hidden" Name="PressPageNum" Value="<% =absPageNum %>">
<Center><%
If absPageNum>1 Then '若当前页不是第一页,则显示上一页链接
Response.Write "<Input Type=Submit Name=Submit Value=上一页>"
End If
If absPageNum<>TotalPages Then '若当前页不是最后一页,则显示下一页链接
Response.Write "<Input Type=Submit Name=Submit Value=下一页>"
End If
%>
</Center>
</Form>
<P><Center>[第<Font Color="#CC0033"><% =absPageNum %></Font>页,共<Font Color="#CC0033"><% =TotalPages %></Font>页]</Center></P>
</Body>
</Html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?