分页显示时如何让数据库只做一次查询?以后各页不再对数据库做查询,而直接显示记录集里的数据!

smartufo 2003-01-10 02:07:52
分页显示时如何让数据库只做一次查询?以后各页不再对数据库做查询,而直接显示记录集里的数据!
...全文
168 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
happylife168 2003-01-10
  • 打赏
  • 举报
回复
我想asp里面的分页应该可以吧,
速度慢,主要是原因读数据、写屏、存储
如果放在客户端分页显示,不是要先把数据存入数组,读写数组都是很慢的
linday 2003-01-10
  • 打赏
  • 举报
回复
你只要用
'Create an instance of the dhtmlGetRows class
Dim objPagedResults
Set objPagedResults = new dhtmlGetRows

objPagedResults.THString = "<th>Views</th><th>FAQ Question</th>"
Response.Write objPagedResults.GenerateHTML(objRS)

'Clean up...
Set objPagedResults = Nothing

调用。
linday 2003-01-10
  • 打赏
  • 举报
回复
我这里有个查询之后放在客户端的分页;程序(是个类):

<%
Class dhtmlGetRows

'******* PRIVATE MEMBER VARIABLES **********
Private iRecsPerPage
Private strTHString
'*******************************************

'************ Initialize Event *************
Private Sub Class_Initialize()
iRecsPerPage = 10 'assign a default value
End Sub
'*******************************************


'************ PROPERTY LET/GET *************
Public Property Let THString(strValue)
'Replace all apostrophes with \'
strTHString = Replace(strValue, "'", "\'")
End Property

Public Property Get THString()
THString = strTHString
End Property


Public Property Let RecsPerPage(iValue)
If iValue > 0 and IsNumeric(iValue) then
iRecsPerPage = CInt(iValue)
End If
End Property

Public Property Get RecsPerPage()
RecsPerPage = iRecsPerPage
End Property
'*******************************************


'**************** METHODS ******************
Public Function GenerateHTML(objRS)

'Begin by getting an array of the data
Dim aValues
aValues = objRS.GetRows()

'Find the value of rows and columns
Dim iCols, iRows
iCols = UBound(aValues, 1)
iRows = UBound(aValues, 2)

Dim strOutput
'Display the initial script block
strOutput = "<body>" & vbCrLf & "<div id=""grid""> </div>" & vbCrLf&"<script language=""javascript"">" & vbCrLf & _
"var tableRow = new Array(" & iRows & ");" & vbCrLf & vbCrLf

Dim iLoop, iColLoop, strTmp
For iLoop = 0 to iRows
strOutput = strOutput & "tableRow[" & iLoop & "] = '<tr>"

For iColLoop = 0 to iCols
'Fix apostrophes
strTmp = Replace(aValues(iColLoop, iLoop),"'", "\'")

'Remove carraige returns
strTmp = Replace(strTmp, vbCrLf, "")

strOutput = strOutput & "<td>" & strTmp & "</td>"
Next 'iColLoop

strOutput = strOutput & "</tr>';" & vbCrLf
Next 'iLoop

'Init global varaibles and find out what browser the user is using
strOutput = strOutput & vbCrLf & vbCrLf & "var first = 0;" & vbCrLf & _
"var last = " & iRecsPerPage & ";" & vbCrLf & _
"var mynav;" & vbCrLf & "if (navigator.appName == ""Netscape"")" & _
vbCrLf & vbTab & "mynav = ""NS"";" & vbCrLf & _
"if (navigator.appName == ""Microsoft Internet Explorer"")" & _
vbCrLf & vbTab & "mynav = ""IE"";" & vbCrLf & _
vbCrLf & "</script>" & vbCrLf & vbCrLf

'Now display the HTML table
strOutput = strOutput & _
vbCrLf & vbCrLf & "<script language=""javascript"">" & vbCrLf


'Write the nav function
strOutput = strOutput & "function nav(iVal) {" & vbCrLf & _
"// do we want to move forward or backwards?" & vbCrLf & _
"if (iVal == 1) { " & vbCrLf & vbTab & "first += " & _
iRecsPerPage & ";" & vbCrLf & "last += " & iRecsPerPage & _
vbCrLf & "}" & vbCrLf & "else if (iVal == -1) { " & vbCrLf & vbTab & _
"first -= " & iRecsPerPage & ";" & vbCrLf & vbTab & "last -= " & _
iRecsPerPage & ";" & vbCrLf & "}" & vbCrLf & _
vbCrLf & vbCrLf & "var txt = '';" & vbCrLf & _
"txt+= '<table border=""1"">';" & vbCrLf

'Do we need to add a TH string?
If Len(strTHString) > 0 then
strOutput = strOutput & "txt+= '<tr>" & strTHString & "</tr>';" & vbCrLf
End If

strOutput = strOutput & "for (var iLoop = first; iLoop < last; iLoop++)" & vbCrLf & _
vbTab & "if (iLoop <= " & iRows & ") txt+= tableRow[iLoop];" & vbCrLf & _
"txt+= '</table>';" & vbCrLf & vbCrLf

'Now, show next/prev links if applicable
strOutput = strOutput & "if (first > 0) // show prev link" & vbCrLf & _
vbTab & "txt+= '<a href=""javascript:nav(-1);"">Prev " & _
iRecsPerPage & "</a> ';" & vbCrLf & vbCrLf & _
"if (last <= " & iRows & ") // show next link" & vbCrLf & vbTab & _
"txt+= '<a href=""javascript:nav(1);"">Next " & _
iRecsPerPage & "</a>';" & vbCrLf & vbCrLf

'Write out the new HTML content to the DIV tag
strOutput = strOutput & "// write out the the DIV tag depending on browser..." & vbCrLf & _
"if (mynav == ""NS"") {" & vbCrLf & vbTab & _
"document.layers['grid'].document.write(txt);" & vbCrLf & vbTab & _
"document.close();" & vbCrLf & "}" & vbCrLf & vbCrLf & _
"if (mynav == ""IE"")" & vbCrLf & vbTab & _
"document.all['grid'].innerHTML =txt;" & vbCrLf & vbCrLf & _
"}" & vbCrLf & vbCrLf

strOutput = strOutput & "nav(0);" & vbCrLf & "</script>"

GenerateHTML = strOutput
End Function
'*******************************************
End Class

%>
smartufo 2003-01-10
  • 打赏
  • 举报
回复
有没有提高速度的分页显示代码?
smartufo 2003-01-10
  • 打赏
  • 举报
回复
wangyime(我很菜,但我很努力)!我的sql语句联合4个表查询,查出的记录有30多万条。怎么把它数组的形式写到客户端?有例子吗?
fj47 2003-01-10
  • 打赏
  • 举报
回复
<!--#include file="conn.asp"-->
<%
dim rs,sql
set rs=server.createobject("adodb.recordset")
sql="select * from user where stoped=0 and passed=1 order by u_id desc"
rs.open sql,conn,1,1
pgsize=20
page=request.querystring("page")
rs.pagesize=pgsize
pgnm=rs.pagecount
if page=""or clng(page)<1 then page=1
if clng(page)>pgnm then page=pgnm
if pgnm>0 then rs.absolutepage=page
i=0
%>
<html>
<head>
<title>会员名单</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#FF9900" leftmargin="5" topmargin="5">
<%if rs.recordcount>0 then%>
<table width="96%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" class="admin">
<tr align="center">
<td width="10%">帐号</td>
<td width="13%">昵称</td>
<td width="10%">姓名</td>
<td width="20%">电子邮箱</td>
<td width="15%">省份/城市</td>
<td width="18%">电话/手机</td>
<td width="10%">操作</td>
</tr>
<%do while not(rs.eof) and i<rs.pagesize%>
<tr align="center">
<td width="10%"><%=rs("userid")%></td>
<td width="13%"><a href="viewreg.asp?u_id=<%=rs("u_id")%>" target="_blank"><%=rs("netname")%></a></td>
<td width="10%"><%=rs("name")%> </td>
<td width="23%"><%=rs("email")%></td>
<td width="15%"><%=rs("province")%>--<%=rs("city")%> </td>
<td width="18%"><%if rs("tel")<>"0" then%><%=rs("tel")%><%end if%><%if rs("mobile")<>"0" then%>/<%=rs("mobile")%><%end if%> </td>
<td width="10%"><a href="#" onClick="window.open('viewreg.asp?u_id=<%=rs("u_id")%>','查看用户资料','toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=120; left=30; height=300,width=256')" target="_self">查看</a>/<a href="delusr.asp?u_id=<%=rs("u_id")%>">删除</a></td>
</tr>
<%i=i+1
rs.movenext
loop%>
</table>
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="5"></td></tr>
</table>
<%if pgnm>1 then%>
<TABLE width="96%" BORDER="1" CELLSPACING="0" CELLPADDING="0" CLASS="admin" BORDERCOLOR="#000000">
<tr>
<td align="center" width="16%">共<font color=#ff0000><%=pgnm%></font>页</td>
<td align="center" width="16%">当前第<%=page%>页</td>
<td align="center" width="16%"><%if page<>1 then%><a href=reglist.asp?page=1>首页</a><%else%>首页<%end if%></td>
<td align="center" width="16%"><%if clng(page-1)<>0 then%><a href=reglist.asp?page=<%=page-1%>>上页</a><%else%>已是首页<%end if%></td>
<td align="center" width="16%"><%if clng(page+1)<>clng(pgnm+1) then%><a href=reglist.asp?page=<%=page+1%>>下页</a><%else%>已是末页<%end if%></td>
<td align="center" width="16%"><%if clng(page)<>clng(pgnm) then%><a href=reglist.asp?page=<%=pgnm%>>末页</a><%else%>末页<%end if%></td>
</tr>
</table>
<%end if%>
<%else%>
<p align=center style=font-size:13px>当前没有申请名单!</p>
<%end if%>
</body>
</html>
wangyime 2003-01-10
  • 打赏
  • 举报
回复
把所有数据都以数组的形式写到客户端,然后写分页的客户端事件
m1_1m 2003-01-10
  • 打赏
  • 举报
回复
本来分页默认的就是只查一次呀

28,408

社区成员

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

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