PDA

View Full Version : Returning 10 DB results per page (ASP/ACCESS)



burns
February 13th, 2006, 03:11 PM
Hi,

I have an ASP search page where all the results are returned but I would like to be able to have 10 results per page. Would this involve substantial changes to the code I have already written?

Any tips, thanks in advance.

DDD
February 13th, 2006, 03:53 PM
we would have to see the code you have already written.

burns
February 13th, 2006, 04:24 PM
we would have to see the code you have already written.

sorry, its a bit messy i know!



<table cellspacing="0" cellpadding="5" border="0" height="100%" width="500">
<tr>
<td class="admintext"> <table height="100%" width="500" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" class="admintext">
<!--#include file="includes/inc_AdminMenuMini.asp" -->
<h2>Property Search - Results</h2>

<%
If Request.Form("minprice") = "" Then
minprice = 1
Else
minprice = Request.Form("minprice")
End If

If Request.Form("maxprice") = "" Then
maxprice = 9999999
Else
maxprice = Request.Form("maxprice")
End If

beds = Request.Form("beds")
Status = Request.Form("Status")


arrType = Split(Replace(Request.Form("type")," ",""),",")
arrArea = Split(Replace(Request.Form("area")," ",""),",")

' // TYPE
intType = UBound(arrType)
If intType => 0 Then
QueryType = "AND ("
For x = 0 To intType
QueryType = QueryType & "Type LIKE '%"&arrType(x)&"%'"
If x < intType Then
QueryType = QueryType & " OR "
End If
Next
QueryType = QueryType & ") "
Else
QueryType = "AND (0 = 0) "
End If

' // AREA
intArea = UBound(arrArea)
If intArea => 0 Then
QueryArea = "AND ("
For y = 0 To intArea
QueryArea = QueryArea & "Area LIKE '%"& arrArea(y)&"%'"
If y < intArea Then
QueryArea = QueryArea & " OR "
End If
Next
QueryArea = QueryArea & ") "
Else
QueryArea = "AND (0 = 0) "
End If

If Status = "Sale" Then
plong_Query = "SELECT * FROM tblProperty WHERE Status = 'Sale' AND (Beds >= " & beds & ") AND (price >= " & minprice & " AND price <= " & maxprice & ") "& QueryType &" "& QueryArea &" ORDER BY price DESC"

End If

If Status = "Resale" Then
plong_Query = "SELECT * FROM tblProperty WHERE Status = 'Resale' AND (Beds >= " & beds & ") AND (price >= " & minprice & " AND price <= " & maxprice & ") "& QueryType &" "& QueryArea &" ORDER BY price DESC"

End If

If Status = "both" Then
plong_Query = "SELECT * FROM tblProperty WHERE (Beds >= " & beds & ") AND (price >= " & minprice & " AND price <= " & maxprice & ") "& QueryType &" "& QueryArea &" ORDER BY price DESC"
End If



Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open plong_Query, dbConnection, adOpenStatic, adLockOptimistic

If RS.EOF Then
Response.Write "<h2>No matching properties found</h2>" & vbNewLine
Response.Write "<p>Sorry! Your search found no matching properties in our database.<br>" & vbNewLine
Response.Write "Please "
Else
Response.Write "<p>Your search found <strong>" & RS.RecordCount & "</strong> matching propert"
If RS.RecordCount = 1 Then
Response.Write "y "
Else
Response.Write "ies "
End If
Response.Write "in our database.<br>" & vbNewLine
Response.Write "You may "
End If

Response.Write "<a href=""javascript:history.back(1)"" class=""admintext"">return to your search</a> and modify it.</p>" & vbNewLine
Response.Write "<p><strong>Please note.</strong> If a property is highlighted as <span class=""underoffer"">Under offer</span> you may still register an interest in case of problems with the sale.</p>" & vbNewLine

Do Until RS.EOF
w = 0
arrDescBrief = Split(RS("Description")," ")
DispAddress = RS("DispAddress")
Price = FormatCurrency(RS("Price"),0)
Beds = RS("Beds")
PropCode = RS("PropCode")
Status = RS("Status")

Response.Write "<table cellspacing=""0"" cellpadding=""0"" border=""0"" class=""admintext""><tr><td valign=""top"">"

Response.Write "<div class=""salesresultsBox"" onMouseOver=""this.style.background='#050154'"" onMouseOut=""this.style.background='#0844F4'"" onClick=""window.location.href='details.asp?id=" & RS("ID") & "';"" style=""cursor:pointer;"" title=""Click for more details"">" & vbNewLine
'Response.Write " <a class=""picborder"" href=""details.asp?id=" & RS("ID") & """><img border=""0"" 'src=""img_size.asp?img=" & PropCode & "_1&w=" & imgResults & """ align=""left"" alt=""" & DispAddress & " '- click for more details""></a>" & vbNewLine
Response.Write " <a href=""details.asp?id=" & RS("ID") & """><img border=""0"" src=""../images/pics/" & PropCode & "_1.jpg"" width=" & imgresults & " title=""Click for more details"" alt=""Click for more details"" align=""left"" class=""picborder""></a>" & vbNewLine

Response.Write "</td><td valign=""top"">"

If RS("UnderOffer") = True Then
Response.Write " <span class=""underoffer"">Under offer</span><br>" & vbNewLine
End If
Response.Write " <strong>" & DispAddress & " - " & Price & "<br>" & vbNewLine
Response.Write " " & Beds & " bedroom"
If RS("beds") > 1 Then
Response.Write "s"
End If
Response.Write "</strong><br>" & vbNewLine
Response.Write " <span class=""tinytext"">"
If UBound(arrDescBrief) > introwords Then
Do Until w = introwords
Response.Write arrDescBrief(w) & " "
w = w + 1
Loop
Else
Response.Write RS("Description")
End If
Response.Write "..." & "<br><br>" & vbNewLine
Response.Write " </span>" & vbNewLine
response.Write "<br><br><br><br>" & vbNewLine
Response.Write " <span class=""medtext"">• <a href=""details.asp?id=" & RS("ID") & """ class=""admintext"">More details <span style=""font-weight:normal;"">or request a viewing</span></a></span>" & vbNewLine
Response.Write "</div>" & vbNewLine

Response.Write "</td></tr></table>"

Response.Write "<hr color=""#FFFFFF"">" & vbNewLine
Response.Write vbNewLine
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
%>
</td>

</tr>
</table>

</td></tr></table>

pixelisfun
February 13th, 2006, 05:54 PM
well this is indeed a bunch of code, but the key is to make the select statement using the LIMIT keyword like this:

SELECT * FROM my_table LIMIT (0,10)

where 0 is the first record (this works like arrays usually work, beginning by 0) and 10 is the number of rows returned.

then you use your asp code to generate the sql on the fly, and being the 0 a variable that you update every time you are changing the page, so first time value will be 0, but next time will be 0 + 10 * num of pages...

an easy way to do it automatically is to use the formula
$offet = (0 + (10 * $page - 1))

this way, first page will begin with record 0, as $page is 1 less 1 * 10 which is 0, and second page will begin with record 10 and so on...

i hope you get the idea...