General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 24th, 2002, 12:43 PM
Johnie Johnie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: North Devon - England
Posts: 20 Johnie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 5 sec
Reputation Power: 0
Problem paging through results

I'm creating an ASP site working with a mySQL database. I've used all this code before and it has worked fine. This time I'm having a problem being able to generate next and previous links.

this is my results processing code, connection through an inclusive file which is working okay throughout all the other pages:

<%
Dim rsNamesrch
Dim strNamesrch
Dim namesearchterm
Dim CountName
Dim TotalPages
Dim CurPage
Const NumPerPage = 2

If Request.Querystring("namesearch") = "" THEN
namesearchterm = Request.Form("namesearch")
ELSE
namesearchterm = Request.Querystring("namesearch")
END If

If Request.Querystring("Curpage") = "" THEN
CurPage = 1
ELSE
CurPage = Request.Querystring("Curpage")
END If

Set rsNamesrch = Server.CreateObject("ADODB.Recordset")
strNamesrch = "SELECT * FROM Tablename WHERE tName LIKE '%" & namesearchterm & "%' ORDER BY tName ASC"
rsNamesrch.Open strNamesrch, strCon

rsNamesrch.MoveFirst
rsNamesrch.PageSize = NumPerPage
TotalPages = rsNamesrch.PageCount
rsNamesrch.AbsolutePage = CurPage
CountName = 0
Dim NameDesc


Do While Not rsNamesrch.EOF AND CountName < rsNamesrch.PageSize

response.write ("<table width='400' border='0' cellspacing='0' cellpadding='5' align='center'>")
response.write ("<tr><td bgcolor='#999999'><font face=verdana size=3><a href='display.asp?ID=") & rsNamesrch("clientID") & ("'>") & rsNamesrch("tName") & ("</a></font></td></tr>")
response.write ("<tr><td bgcolor='#CCCCCC'><font face=verdana size=2><a href='display.asp?ID=") & rsNamesrch("clientID") & ("'>View full details</a></font></td></tr>")
response.write ("<tr><td>&nbsp;</td></tr></table><br>")
CountName = CountName + 1
rsNamesrch.MoveNext
Loop


If CurPage > 1 THEN
response.write ("<p align='center'><font face='Verdana' size='2'><b><A href='testresults.asp?Curpage=") & CurPage - 1 & ("&namesearch=") & namesearchterm & ("'>Previous</A>")
ELSE
response.write ("<p align='center'><font face='Verdana' size='2'><b>")
END If

response.write (" ... Page ") & CurPage & (" of ") & TotalPages & (" ... ")

If Cint(CurPage) <> Cint(TotalPages) THEN
response.write ("<A href='testresults.asp?Curpage=") & CurPage + 1 & ("&namesearch=") & namesearchterm & ("'>Next</A></b></font></p>")
ELSE
response.write ("</b></font></p>")
End If


rsNamesrch.Close
Set adoConn = Nothing
Set strCon = Nothing
Set rsNamesrch = Nothing
%>

This code generates the first results, but the PageCount and AbsolutePage don't seem to generate anything or accept a value and the next and previous links don't appear.

If I comment out AbsolutePage I get the next link but just to show the first two results over and over again endlessly. The TotalPages value stays at '1' even when there are more results than the pages NumPerPage.

Can anyone suggest an alternate method of code to limit the results per page and where next and previous links can be generated when appropriate?

Or spot what's wrong with this one?

I've tried using LIMIT and offset, but I cannot get the syntax right in my select statement

A previous site I've written using ASP, with a mySQL database, with the same hosting company uses the same code and it works fine. I've even recreated the table on that sites mySQL database, changed the inclusive file for the connection and this code works perfectly on the other site.

I've spent days on this, any ideas would be welcome

Johnie

Reply With Quote
  #2  
Old December 24th, 2002, 03:37 PM
neurosis neurosis is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 6 neurosis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try your loop like this


Do While Not rsNamesrch.EOF and rsNamesrch.AbsolutePage = curPage

instead of

Do While Not rsNamesrch.EOF AND CountName < rsNamesrch.PageSize

Reply With Quote
  #3  
Old December 24th, 2002, 03:55 PM
Johnie Johnie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: North Devon - England
Posts: 20 Johnie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 5 sec
Reputation Power: 0
I'm afraid it's the same result.

The initial results appear to be the same, but it still does not generate the links to the next page.

If I force the URL with telling it, it is page 2 (?Curpage=2&namesearch=e)

it generates a previous and next button, but it states it is page 2 of 1 .. and then not all the results that should be returned are rerturned. Some are missed entirely.

If I comment out the code about PageCount and AbsolutePage and the code to generta the links, and have no limit on a page then .. EVERY coressponding result is returned.

So my problem seems to centre around finding a method of limiting the results per page and generating the next and previous links when they are necessary.

Johnie

Reply With Quote
  #4  
Old January 13th, 2003, 11:54 AM
Johnie Johnie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: North Devon - England
Posts: 20 Johnie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 5 sec
Reputation Power: 0
The Solution

It ended up that the server was not giving up any correct value within pagecount and absolute page.

My hosting company deleted my web site and gave me space on a new server. I uploaded my entire site, recreated my database.

And

Voila

The code just worked perfectly.

Live and learn!

Johnie

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Problem paging through results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT