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... 1

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>
 
I will paste in a example of doing paging. I borrowed it from a site but can't remember where so I can't give credit, but it does the job.

EXAMPLE - if you copy and paste into wordpad it will be formmatted better.

<!-- #include file=&quot;ConnectInclude.asp&quot; -->

<%
' Declare all of the variables that will be used in the page.
Dim objRst ' ADO Recordset Object
Dim strYear ' The year that we are searching for.
Dim Sql ' Our SQL statement
Dim intPageCount ' The number of pages in the recordset.
Dim intRecordCount ' The number of records in the recordset.
Dim intPage ' The current page that we are on.
Dim intRecord ' Counter used to iterate through the recordset.
Dim intStart ' The record that we are starting on.
Dim intFinish ' The record that we are finishing on.

' Check to see if there is value in the NAV querystring. If there
' is, we know that the client is using the Next and/or Prev hyperlinks
' to navigate the recordset.
If Request.QueryString(&quot;NAV&quot;) = &quot;&quot; Then
intPage = 1
Else
intPage = Request.QueryString(&quot;NAV&quot;)
End If

' Connection Object created in the include file

' Query

Sql = &quot;Select ShopOrders.shopOrderNumber, ShopOrders.receivedDate, &quot; & _
&quot;ShopOrders.customerPurchaseOrder, Customer.customerID, &quot; & _
&quot;Nameplate.customerMotorNumber, Equipment.equipmentName, &quot; & _
&quot;Equipment.equipmentType, Nameplate.hp, Nameplate.model &quot; & _
&quot;FROM ShopOrders, Equipment, Nameplate, Customer &quot; & _
&quot;WHERE (Customer.CustomerID = &quot; & Session(&quot;customerID&quot;) & &quot;) &quot; & _
&quot; and (ShopOrders.shopOrderNumber = Equipment.shopOrderNumber &quot; & _
&quot; and Nameplate.equipmentKey = Equipment.equipmentKey &quot; & _
&quot; and Customer.customerID = ShopOrders.customerID ) &quot; & _
&quot;ORDER BY ShopOrders.shopOrderNumber; &quot;

' Create you Recordset Object
Set objRst = Server.CreateObject(&quot;ADODB.Recordset&quot;)

' The CursorLocation and the CursorType must be set as they are here
' in order for Recordset Paging to work properly.
objRst.CursorLocation = 3 'adUseClient
objRst.CursorType = 3 'adOpenStatic
objRst.ActiveConnection = objConn

' Open the recordset.
objRst.Open Sql, objConn, adOpenStatic, adLockReadOnly

' Set the PageSize, CacheSize, and populate the intPageCount and
' intRecordCount variables.
objRst.PageSize = 5
' The cachesize property sets the number of records that will be cached
' locally in memory.
objRst.CacheSize = objRst.PageSize
intPageCount = objRst.PageCount
intRecordCount = objRst.RecordCount


' Now you must double check to make sure that you are not before the start
' or beyond end of the recordset. If you are beyond the end, set
' the current page equal to the last page of the recordset. If you are
' before the start, set the current page equal to the start of the recordset.
If CInt(intPage) > CInt(intPageCount) Then intPage = intPageCount
If CInt(intPage) <= 0 Then intPage = 1

' Make sure that the recordset is not empty. If it is not, then set the
' AbsolutePage property and populate the intStart and the intFinish variables.
If intRecordCount > 0 Then
objRst.AbsolutePage = intPage
intStart = objRst.AbsolutePosition
If CInt(intPage) = CInt(intPageCount) Then
intFinish = intRecordCount
Else
intFinish = intStart + (objRst.PageSize - 1)
End if
End If
%>
<BODY bgcolor=&quot;#CCCCCC&quot; text=&quot;#000000&quot; link=&quot;#993300&quot; vlink=&quot;#0000FF&quot; alink=&quot;#FF9900&quot;>
<h3>Browse Shop Orders, returned <%=intRecordCount%> records.</h3>

<%If intRecordCount > 0 Then
' Display the records for the page
' Build the table header
Dim fldF
%>
<table border=1>

<%
'''' Write Header
Response.Write &quot;<tr>&quot;
Response.Write &quot;<td>&quot; & &quot;Shop Order Number&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Received Date&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Customer P.O.&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Customer Motor Number&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Equipment Name&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Equipment Type&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Horse Power&quot; & &quot;</td>&quot;
Response.Write &quot;<td>&quot; & &quot;Model&quot; & &quot;</td>&quot;
Response.Write &quot;</tr>&quot;

' Iterate through the recordset until we reach the end of the page
' or the last record in the recordset.
For intRecord = 1 to objRst.PageSize
'''' Write Row
Response.Write &quot;<tr>&quot;

Response.Write(&quot;<td bgcolor=#00FFFF> <A href=&quot; _
& &quot;ShopOrderInfo.asp?Action=TheKey&Item=&quot; & objRst(&quot;shopORderNumber&quot;) & &quot;>&quot; _
& objRst(&quot;shopORderNumber&quot;) & &quot;</A></td>&quot;)

Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;receivedDate&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;customerPurchaseOrder&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;customerMotorNumber&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;equipmentName&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;equipmentType&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;hp&quot;) & &quot;</td>&quot;
Response.Write &quot;<td bgcolor=&quot; & &quot;#00FFFF&quot; & &quot;>&quot; & objRst(&quot;model&quot;) & &quot;</td>&quot;
Response.Write &quot;</tr>&quot;
objRst.MoveNext
If objRst.EOF Then Exit for
Next
%>
</table>
<table border=2 bgcolor=&quot;#778899&quot;>
<tr><td align=right>
<%
' Check to see if the current page is greater than the first page
' in the recordset. If it is, then add a &quot;Previous&quot; link.
If cInt(intPage) > 1 Then
%>
<a href=&quot;BrowseShopOrder.asp?NAV=<%=intPage - 1%>&YEAR=<%=strYear%>&quot;><< Prev</a>
<%End IF%>
<%
' Check to see if the current page is less than the last page
' in the recordset. If it is, then add a &quot;Next&quot; link.
If cInt(intPage) < cInt(intPageCount) Then
%>
<a href=&quot;BrowseShopOrder.asp?NAV=<%=intPage + 1%>&YEAR=<%=strYear%>&quot;>Next >></a>
<%End If%>
</td>
<td align=right>
<B>Viewing records <%=intStart%> through <%=intFinish%></B>
</td>
</tr>
</table>
<%End If%>
</BODY>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top