<%
dim connect, rs, sql, ctr,recaddr, pagenum, totrs, gotopg, pg
pg = request.form("pg")
ctr = request.form("ctr")
pagenum = request.form("pagenum")
if pg = "" then pg = 1
if request.form("ctr") = "" then ctr = "first"
if request.form("pagenum") = "" then pagenum = 1
set connect = server.createobject("ADODB.Connection")
connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_
Server.MapPath("\perlphpasp\db\casereg.mdb"))
sql = "select * from student order by idstd"
set rs = server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrs = rs.recordcount
if totrs > 0 then
select case ctr
case "first"
pagenum = 1
case "previous"
if pagenum = 1 then
pagenum = totrs
else
pagenum = pagenum - 1
end if
case "next"
tnext = totrs
if int(pagenum) >= int(tnext) then
pagenum = 1
else
pagenum = pagenum + 1
end if
case "last"
pagenum = totrs \ pg
rest = totrs mod pg
if rest > 0 then
pagenum = pagenum + 1
end if
end select
calgoto = int(pg) * (int(pagenum) - 1)
if pagenum = 1 or calgoto > totrs then
gotopg = 0
else
gotopg = calgoto
end if
rs.move gotopg
n = gotopg + 1
response.write(" Current: "& pagenum &" / "& totrs &_
" Start record: "& n &"<br>")
for i = 1 to pg
if not rs.eof then
response.write(n&". "&rs("idstd")&" - "&rs("stname")&" - "&_
rs("stsurn")&" - "&rs("advid")&" - "&rs("major")&"<br>")
rs.movenext
end if
n = n + 1
next
else
response.write("Record not found")
end if
connect.close
set rs = nothing
set connect = nothing
response.write("<hr><form action=listpage.asp method=post>" &_
"Rec/Page: <input name=pg value="& pg & ">" &_
"Page no: "& pagenum & "<input type=hidden name=pagenum value="& pagenum &"><br>" &_
"<input type=submit name=ctr value=first>" &_
"<input type=submit name=ctr value=previous>" &_
"<input type=submit name=ctr value=next>" &_
"<input type=submit name=ctr value=last></form>")
%>
จำนวน : 71 บรรทัด