在asp中通过getrows实现数据库记录分页的一段代码
程序员文章站
2023-10-27 14:18:16
复制代码 代码如下:<%@ language = vbscript %> <% option...
复制代码 代码如下:
<%@ language = vbscript %>
<% option explicit %>
<%
rem 在asp中通过getrows实现数据库记录分页的一段代码
dim istart, ioffset
istart = request("start")
ioffset = request("offset")
if not isnumeric(istart) or len(istart) = 0 then
istart = 0
else
istart = cint(istart)
end if
if not isnumeric(ioffset) or len(ioffset) = 0 then
ioffset = 30
else
ioffset = cint(ioffset)
end if
response.write "viewing " & ioffset & " records starting at record " & istart & "<br>"
dim objconn, objrs
set objconn = server.createobject("adodb.connection")
'objconn.open "dsn=mp3"
dim connstr
dim db
db="csnjimageman.mdb"
connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
objconn.open connstr
set objrs = server.createobject("adodb.recordset")
objrs.open "select * from imageinfo", objconn
dim aresults
aresults = objrs.getrows
objrs.close
set objrs = nothing
objconn.close
set objconn = nothing
dim irows, icols, irowloop, icolloop, istop
irows = ubound(aresults, 2)
icols = ubound(aresults, 1)
if irows > (ioffset + istart) then
istop = ioffset + istart - 1
else
istop = irows
end if
for irowloop = istart to istop
for icolloop = 0 to icols
response.write aresults(icolloop, irowloop) & " "
next
response.write "<br>"
next
response.write "<p>"
if istart > 0 then
'show prev link
response.write "<a href=""getrows.asp?start=" & istart-ioffset & _
"&offset=" & ioffset & """>previous " & ioffset & "</a>"
end if
if istop < irows then
'show next link
response.write " <a href=""getrows.asp?start=" & istart+ioffset & _
"&offset=" & ioffset & """>next " & ioffset & "</a>"
end if
%>
<% option explicit %>
<%
rem 在asp中通过getrows实现数据库记录分页的一段代码
dim istart, ioffset
istart = request("start")
ioffset = request("offset")
if not isnumeric(istart) or len(istart) = 0 then
istart = 0
else
istart = cint(istart)
end if
if not isnumeric(ioffset) or len(ioffset) = 0 then
ioffset = 30
else
ioffset = cint(ioffset)
end if
response.write "viewing " & ioffset & " records starting at record " & istart & "<br>"
dim objconn, objrs
set objconn = server.createobject("adodb.connection")
'objconn.open "dsn=mp3"
dim connstr
dim db
db="csnjimageman.mdb"
connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(""&db&"")
objconn.open connstr
set objrs = server.createobject("adodb.recordset")
objrs.open "select * from imageinfo", objconn
dim aresults
aresults = objrs.getrows
objrs.close
set objrs = nothing
objconn.close
set objconn = nothing
dim irows, icols, irowloop, icolloop, istop
irows = ubound(aresults, 2)
icols = ubound(aresults, 1)
if irows > (ioffset + istart) then
istop = ioffset + istart - 1
else
istop = irows
end if
for irowloop = istart to istop
for icolloop = 0 to icols
response.write aresults(icolloop, irowloop) & " "
next
response.write "<br>"
next
response.write "<p>"
if istart > 0 then
'show prev link
response.write "<a href=""getrows.asp?start=" & istart-ioffset & _
"&offset=" & ioffset & """>previous " & ioffset & "</a>"
end if
if istop < irows then
'show next link
response.write " <a href=""getrows.asp?start=" & istart+ioffset & _
"&offset=" & ioffset & """>next " & ioffset & "</a>"
end if
%>