Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Database Recordsets Paging...

Status
Not open for further replies.
Jan 10, 2002
2
MX
Ok I tried some paging scripts around but they donesn´t worked, so here´s my recordset script, Can someone help me to divide the results in pages?
ok Here it is:
<%Option Explicit%>
<!--#INCLUDE FILE=&quot;format.inc&quot;-->
<%
dim Conn, RS, ID
Set Conn = GetConnection
Response.Buffer=True
if &quot;&quot; & Request.QueryString(&quot;ID&quot;) <> &quot;&quot; and isnumeric(Request.QueryString(&quot;ID&quot;)) then
'If there is an ID in QUERY_STRING
'Write file from db to the client
ID = Clng(Request.QueryString(&quot;ID&quot;))

if ucase(Request.QueryString(&quot;A&quot;))=&quot;D&quot; then'Delete
Conn.execute(&quot;delete from Upload where UploadID=&quot; & ID)
Else'Download
'file record
Set RS = Conn.execute(&quot;select * from Upload where UploadID=&quot; & ID)
if ucase(Request.QueryString(&quot;A&quot;))<>&quot;P&quot; then
response.contenttype = RS(&quot;ContentType&quot;)'set Content-Type
Response.AddHeader &quot;Content-Disposition&quot;, &quot;attachment;filename=&quot;&quot;&quot; & RS(&quot;SouceFileName&quot;) & &quot;&quot;&quot;&quot;
End If

' Response.BinaryWrite RS(&quot;Data&quot;).Value 'Write the file from db field to the client
Response.BinaryWrite RS(&quot;Data&quot;).GetChunk(RS(&quot;DataSize&quot;)) 'Write the file from db field to the client

RS.Close
Conn.Close
Response.End
End If'Download
End If

response.write Head(&quot;7-Replays&quot;, &quot;Replay Database&quot;)
response.write DBList(Conn)
Conn.Close

function DBList(Conn)
dim HTML, RS, ContentType
'Open recordset with the files
Set RS = Conn.execute(&quot;select UploadID, SouceFileName, Ganador, Razag, Perdedor, Razap, Mapa, ContentType from Upload order by UploadDT desc&quot;)
HTML = HTML & &quot;<Table><tr><th ColSpan=3><font face=Arial color=silver size=3>Replays : </font></th></tr>&quot; & vbcrlf
HTML = HTML & &quot;<Table><tr><th ColSpan=2><font face=Arial color=silver size=1>Sube tus Replays <a href= & vbcrlf
HTML = HTML & &quot;<tr><th bgcolor=gray><strong><font face=Arial color=silver size=2>D/l</font></strong></th><th bgcolor=gray><strong><font face=Arial color=silver size=2>Ganador</font></strong></th><th bgcolor=gray><strong><font face=Arial color=silver size=2>Perdedor</font></strong></th><th bgcolor=gray><strong><font face=Arial color=silver size=2>Mapa</font></strong></th></tr>&quot; & vbcrlf
do while not RS.Eof
ContentType = lcase(&quot;&quot; & RS(&quot;ContentType&quot;))
HTML = HTML & &quot;<tr><td> <A HREF=&quot; & Request.ServerVariables(&quot;SCRIPT_NAME&quot;) & &quot;?ID=&quot; & RS(&quot;UploadID&quot;)
if left(ContentType,6)=&quot;image/&quot; or left(ContentType,5)=&quot;text/&quot; then
HTML = HTML & &quot; onmouseover=&quot;&quot;ShowFile('&quot; & RS(&quot;UploadID&quot;) & &quot;')&quot;&quot; onmouseout=&quot;&quot;HideFile()&quot;&quot;&quot;
end if
HTML = HTML & &quot;><img border=0 src=dl.gif>&quot; & &quot;</A>&quot;
HTML = HTML & &quot; </td><td><strong><font face=Arial size=2>&quot; & RS(&quot;Ganador&quot;) & &quot;</font></strong><font size=1 color=gray>&quot; & RS(&quot;Razag&quot;) & &quot;</font></td><td><strong><font face=Arial size=2>&quot; & RS(&quot;Perdedor&quot;) & &quot;</font></strong><font size=1 color=gray>&quot; & RS(&quot;Razap&quot;) & &quot;</font>&quot;
HTML = HTML & &quot; </td><td><font face=Arial size=2>&quot; & RS(&quot;Mapa&quot;) & &quot;</font></td></tr>&quot; & vbcrlf
RS.MoveNext
loop
HTML = HTML & &quot;</Table>&quot; & vbcrlf
DBList = HTML
RS.Close
end function

function GetConnection()
dim Conn, AuthConnectionString
' AuthConnectionString = &quot;DBQ=&quot; & Server.MapPath(&quot;upload.mdb&quot;) & &quot;;DefaultDir=&quot; & Server.MapPath(&quot;/&quot;) & &quot;;&quot; & _
' &quot;Driver={Microsoft Access Driver (*.mdb)}; DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;UID=;&quot;
AuthConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;upload.mdb&quot;)
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.open AuthConnectionString
set GetConnection = Conn
end function

%>
</Script>
 
right - I can't be arsed to read thru all that, but assuming you want to paginate your results (limit the amount of results shown on any one page) then you basically need to do these things;
- declare and set your recordset (oRs).
- oRs.pagesize = x (x is the number of records to show on one page)
- oRs.chachesize = x
- get the required page (dim iPage, iPage = request(&quot;p&quot;))

- do your query (oRs.open . .)
- dim iPageCount, iPageCount = oRs.pagecount

- if not oRs.eof and iPageCount>0 then - start looping
- oRs.absolutepage = iPage (moves to the required page)
- do while i <= iPageSize and not oRs.EOF
- do your thing
- i=i+1, oRs.movenext, loop

then by calling that page with &quot;?p=1&quot; will show the first page &quot;?p=2&quot; second page, etc.
It's also a good idea to set up a nav panel with &quot;prev&quot;, &quot;next&quot; links and links to each page itself. This can be done similarly to a bit of code along the lines of;
- if iPagecount>1 then - start adding nav section
- if iPage>1 then display a &quot;prev&quot; link with p=iPage-1
- for j=1 to iPageCount display links with p=j
- if iPage<iPageCount then display a &quot;next&quot; link with p=iPage+1

as I always tend to say, check for ths kinda thing - they're damned good for it.

I bet that made no sense at all, did it? Ah well, it is friday . . :p

good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top