初学者疑问,请帮忙

Rain_B 2002-03-10 03:13:57
我有两个小问题,请帮忙
1。请问如何分页显示从数据库查找出来的大量记录?
2。请问session可不可以保存数组对象?
...全文
69 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonnycncn 2002-03-10
  • 打赏
  • 举报
回复
给你一个分页程序吧,
照着修改就行了,

<%@ Language=VBScript %>
<%
function getFormObject ()
if Request.ServerVariables("REQUEST_METHOD") = "GET" then
set getFormObject=Request.QueryString
else
set getFormObject=Request.Form
end if
end function
set oFormVars=GetFormObject()
if inStr(UCase(oFormVars("Action")),"索") > 0 then
session("xinxisearch")="select * FROM xxx where Feed_Title like ''%"&Request.Form ("name")&"%'' ORDER BY Feed_Date DESC"
session("search")=Request.Form ("name")
end if
%>
<HTML><HEAD><TITLE>信息网</TITLE>
<!-- #INCLUDE VIRTUAL="ADOVBS.inc" -->
<META content=text/html;charset=gb2312 http-equiv=Content-Type>
<STYLE type=text/css>TD {FONT-FAMILY: 宋体; FONT-SIZE: 9pt}
P {FONT-FAMILY: 宋体; FONT-SIZE: 9pt}
DIV {FONT-FAMILY: 宋体; FONT-SIZE: 9pt}
BODY {BACKGROUND-COLOR: #ffffff; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; MARGIN-LEFT: 0px; MARGIN-TOP: 0px}
A {COLOR: #0000aa; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; TEXT-DECORATION: underline}
A:active {COLOR: #ff8019; TEXT-DECORATION: underline}
A.top { COLOR: #ffffff; FONT-SIZE: 9pt}
A.ns {FONT-SIZE: 12pt}
TD.p16 {FONT-SIZE: 16pt}
TD.p8 {FONT-SIZE: 1pt}
TD.p9 {FONT-SIZE: 9pt}
TD.p20 {FONT-SIZE: 20pt}
TD.p12 {FONT-SIZE: 12pt}
.f11 {FONT-SIZE: 14px}
.f1_v {FONT-SIZE: 9pt; FONT-WEIGHT: 200}
.f2_V { FONT-SIZE: 9pt}
.f3_V { FONT-SIZE: 12pt}
.f4_V { FONT-SIZE: 13.5pt}
.f6_V { FONT-SIZE: 18pt}
A:hover {COLOR: #ff6666; TEXT-DECORATION: none}
.unnamed1 {FONT-SIZE: 9pt}
</STYLE>
</HEAD>
<BODY aLink=#ff9900 bgColor=#ffffff leftMargin=0 link=#003399 text=#000000
topMargin=0 vLink=#000000 MARGINHEIGHT="0" MARGINWIDTH="0">
<hr color="black" size="1">
<img height=16 src="../images/xian.jpg" width=776><br>
<table width="73%">
<tr>
<td> <b>信息检索</b>:</td>
<form method="post" action="text.asp">
<td>
<input class=textfield type="text" name="name" size="20" maxlength="50">
<input class=botton type="submit" name="Action" value="搜索">
</td>
</form>
<form method="post" action="day.asp">
<td>
<select class=textfield name="Days" size=1 style="WIDTH: 130px" width="130">
<option value="1" SELECTED>最近一天</option>
<option value="2">最近两天</option>
<option value="5">最近五天</option>
<option value="7">最近一星期</option>
<option value="14">最近两星期</option>
<option value="30">最近一个月</option>
<option value="60">最近两个月</option>
<option value="120">最近四个月</option>
<option value="365">最近一年</option>
</select>
<input class=botton type="submit" name="Action" value="搜索">
</td>
</form>
</tr>
</table>
<div align="left"> </div>
</CENTER></DIV>
<table width="100%" border="0">
<tr>
<td width="29%"><a href=../index.asp><font size="3" color="#8080C0"><img src="images/0022.gif" width="23" height="8" border="0">回首页</font></a></td>
<td width="39%"> 你搜索的关键字为“<%=session("search")%>”.</td></tr>
<tr>
<td width="29%" valign="top"><a href="index.asp"><img src="images/a000.jpg" width="224" height="300" align="texttop" alt="信息窗栏目首页" border="0"></a><br>
</td>
<td colspan="2" valign="top">

<%
If Request("Page")=Empty Then
Page=1
Else
Page=cint(Request("Page"))
End If
''创建ADO对象
If InStr (Search,"[") <> 0 Or InStr(Search,Chr(39))<>0 then ''若发现不安全字符,则停止执行
Response.Write("<script language=''JavaScript''>history.go(-1)</script>")
Response.End
End If
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionTimeOut = 15
Conn.CommandTimeOut = 30
Conn.Open "ccisn", "", ""

Set rs=Server.CreateObject("ADODB.RecordSet")
''sqlstr="select * FROM xxxx where Feed_Title like ''%"&search&"%'' ORDER BY Feed_Date DESC"
''session("xinxisearch")="select * FROM xinxi where Feed_Title like ''%"&type1&"%'' ORDER BY Feed_Date DESC"
rs.open session("xinxisearch"), conn, adOpenStatic

If rs.Recordcount=0 then
rs.close
conn.close
response.write "目前没有您要找的信息!"
response.end
End If
rs.PageSize=30 ''设置每页的记录数
tcount=rs.RecordCount ''取得所有记录的总数
tpage=rs.PageCount ''取得页面的总数
If Not rs.eof Then
RS.AbsolutePage = PAGE
End If
%>
共有<font color=red><%=tcount%></font>条信息,当前为第<font color=red><%=page%></font>页,共<font color=red><%=tpage%></font>页
   
<%''以下为上一页和下一页的设置
If page>1 Then
Response.write "<a href=text.asp?page="&page-1&">上一页</a> "
End If
Response.write "页 <font face=Arial><b>"&pagecount&" / "
Response.write page &"</b></font> "
For j=1 to tpage
IF J <> page THEN
response.write "<a href=text.asp?page="&j&">"&j&"</a> "
End If
Next
If page<tpage Then
Response.write "<a href=text.asp?page="&page+1&">下一页</a>"
End If

pagecount=rs.pagecount
I=1
do until rs.EOF or I > RS.PageSize
%>
<br>
<li> <a href="reads.asp?MsgID=<%=RS.Fields(0).Value%>" target="_blank">
<% Response.Write RS.Fields(1).Value%>
</a>  <font color="#FF0000"><b>(
<% Response.Write RS.Fields(3).Value%>
)</b></font> ——类别:<%=RS.Fields(2).Value%>
<% rs.MoveNext ''移到下一个记录
I=I+1
loop
rs.close
conn.close
%>
<p><a href=<%=return_to%> >返回</a>
<p>注意:如果您检索时出错,请您在检索时不要用回车,要用鼠标点击搜索按钮!

</td>
</tr></table>
<HR align=center color=#008080 width="95%">
</BODY></HTML>
Rain_B 2002-03-10
  • 打赏
  • 举报
回复
数组可以保存,
对于上面的例子
rstemp.cursorlocation=aduseclient 是什么意思?
rstemp.cachesize=5 还有这一行
rstemp.open mySQL,connectme
rstemp.movefirst

rstemp.pagesize=mypagesize 这一行
maxpages=cint(rstemp.pagecount) 这一行
maxrecs=cint(rstemp.pagesize) 这一行
rstemp.absolutepage=mypage 这一行
howmanyrecs=0 这一行
howmanyfields=rstemp.fields.count -1 这一行

DO UNTIL rstemp.eof OR howmanyrecs>=maxrecs
'....
rstemp.movenext
howmanyrecs=howmanyrecs+1
LOOP
请帮忙解释一下把,我把剩下的分都给他了.
如果谁告诉我哪里有这方面的资料下载,我会另外给分.
纪俊 2002-03-10
  • 打赏
  • 举报
回复
1.用.pagesize与.pagecount属性来解决。
2.可以
applehoo 2002-03-10
  • 打赏
  • 举报
回复
第一个问题:去看看
http://www.csdn.net/expert/topic/543/543889.xml?temp=.9985468
也许对你有帮助。
第二个问题,解决同楼上。
xingworld 2002-03-10
  • 打赏
  • 举报
回复
gz
julyclyde 2002-03-10
  • 打赏
  • 举报
回复
数组不是对象,不用set就可以保存啊
karma 2002-03-10
  • 打赏
  • 举报
回复
1. the easiest way is to use ADO's paging mechanism, but it is inefficient, since the database returns all the records, for example:

set rstemp=Server.CreateObject("ADODB.Recordset")
rstemp.cursorlocation=aduseclient
rstemp.cachesize=5
rstemp.open mySQL,connectme
rstemp.movefirst

rstemp.pagesize=mypagesize
maxpages=cint(rstemp.pagecount)
maxrecs=cint(rstemp.pagesize)
rstemp.absolutepage=mypage
howmanyrecs=0
howmanyfields=rstemp.fields.count -1

DO UNTIL rstemp.eof OR howmanyrecs>=maxrecs
'....
rstemp.movenext
howmanyrecs=howmanyrecs+1
LOOP

rstemp.close

There is a better way. It requires you to construct an appropriate SQL statement or use a stored procedure to return only the records for a specific page. The implementation is data-dependent

2. yes, an example from MSDN:

Dim MyArray()
ReDim MyArray(5)
MyArray(0) = "hello"
MyArray(1) = "some other string"
'Store the array in the Session object
Session("StoredArray") = MyArray
'Now retrieve the array from the Session object
LocalArray = Session("StoredArray")
LocalArray(1) = "there"
...
'and then store the updated one back again
Session("StoredArray") = LocalArray

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧