I have reinvented the wheel. And it only took a day! (Full Version)

All Forums >> [Web Development] >> ASP, PHP, and Database



Message


hzarabet -> I have reinvented the wheel. And it only took a day! (10/19/2003 17:21:44)

In my quest to wean myself off of the DRW, I came to the point of having to build a query that results in more than 1 page. Yow.[:@]

I looked at some "examples" of how to do this on the web but it would have taken me longer to decipher them than to try doing it myself. So i did[:)]!

I set the code up as includes (two of them). I can now drop these includes into my HTML and I'm set! I am including the code below for two reasons:

1. I have gotten so much from all of you, if I can give a crumb back I am pleased!

2. Maybe someone could find fault in the code! It APPEARS to be pretty good.

Heres the deal:

1. On your "results" page you need to include a space to tell the code the number of results per page and a "SELECT COUNT" statement to tell the code the total number of results:

<%
'Set Records Per Page. Replace 30 with your records per page
Dim iRPP
iRPP = "30"
%>

<%
SQL = "SELECT Count(*) AS Total FROM (From this point forward this statement should match the SQL you are using to call the results.)
set RS = conn.execute(SQL)
%>

2. Insert the following (include 1) right after the above SQL:

<%
Dim iTotal
iTotal = RS("Total")

'iPageTotal is number of page of query results
Dim iPageTotal
iPageTotal = iTotal/iRPP

'iPageCount is the page of the query
Dim iPageCount
iPageCount = 0

Dim i, iPN, iStart, iEnd
iPN = Request.QueryString("PN")

If iPN = "" then
iPN = 1
end if
If iPN*iRPP <= iTotal then
iEnd = (iPN*iRPP)-1
Else
iEnd = iTotal-1
end if

If iEnd = iTotal then
iStart = (iPageTotal-1)*iRPP
ElseIf iPN = 1 then
iStart = 0
ElseIf iPN >1 then
iStart = (iPN*iRPP)-iRPP
end if
%>

3. This is set up using getrows. You will need to to modify a typical

<%FOR i = 0 TO Ubound(array,2)%>

to the following (iStart tells the array the first record to use based on the page number you click. iEnd does the last row):

<%For i = iStart to iEnd%>

4. Insert the following (include 2) just before your </body> tag.

<%If iTotal > "&iRPP&" then%>

<%
If Request.QueryString("SortOrder") > "0" then
iSortOrder = "&SortOrder="&Request.QueryString("SortOrder")&""
End if

If (iPageTotal-Int(iPageTotal)) < .50 then
xPageTotal = Round(iPageTotal)+1
Else
xPageTotal = Round(iPageTotal)
end if
%>
<table border="0" width="756" align = "center">
<tr>
<td width="100%" align="right"><font face="Arial" size="2"><b>Page <%=iPN%> of <%=xPageTotal%><br>
Go to:
<%
If iPN <> 1 then
%>
<a href = "..<%=Request.Servervariables("URL")%>?PN=<%=Request.QueryString("PN")-1%><%=iSortOrder%>" style="text-decoration: none">Previous</a> 
<%end if%>
<% Do While iPageCount < iPageTotal %>
<% iPageCount = iPageCount+1%>
<a href = "..<%=Request.Servervariables("URL")%>?PN=<%=iPageCount%><%=iSortOrder%>"><%=iPageCount%></a>
<%Loop%>
<%
If iPN < ""&iPageTotal&"" then
%>
 <a href = "..<%=Request.Servervariables("URL")%>?PN=<%=Request.QueryString("PN")+1%><%=iSortOrder%>" style="text-decoration: none">Next</a><br>
<%end if%>
</b>
</font>
</td>
</tr>
</table>
<%end if%>


I also have code included if a Sort Order querysting is invloved.

That's it. Hope it works for you. In case it needs mentioning [;)], back up first!

Check it here




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875