Count Records and Multiple Pages (Full Version)

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



Message


xterradane -> Count Records and Multiple Pages (9/1/2002 11:25:40)

I am to the point where I need to have multiple pages for search results, but I can' t find the previous code which explained how to implement this. Any ideas where I can find the info or how to do it would be appreciated? Everything is hand coded in ASP.

Gail

[:)]




Spooky -> RE: Count Records and Multiple Pages (9/1/2002 18:46:48)

Heres an example of paging that may be of use?
http://www.learnasp.com/learn/dbtablepaged.asp





xterradane -> RE: Count Records and Multiple Pages (9/6/2002 12:39:26)

Spooky,

I found some other code that seemed a little less complex for me to understand. However, I am having some problems. I can get the results for the first page and the links are fine. I am getting a ADO error and can' t figure out why since it works on the first page. This is the link to the code I followed:

http://aspfree.com/asp/startpage.asp?id=11

This is a link to my page with the results:

http://www.fit-jobs.com/JobSearchResultsPaging.asp?JobType=Any&State=Any&Get+Jobs=Get+Jobs

Here is my code watered down a bit:

<%
	
	Dim iPageSize				' How big our pages are
	Dim strPageCount			' The number of pages we get back
	Dim strPageCurrent		' The page we want to show
	Dim  x						' Standard looping var
	
	iPageSize = 10
	
	If Request(" page" ) = " "  Then
		strPageCurrent = 1
	End If
	
	If Request(" page" ) <> " "  Then
		strPageCurrent = CInt(Request(" page" ))
	End If
		
	Dim strState, strJobType
	strState = Request(" State" )
	strJobType = Request(" JobType" )
	
	Dim rsJob
	Set rsJob = Server.CreateObject(" ADODB.Recordset" )
	rsJob.CursorLocation = adUseClient 	' Set cursor location
	rsJob.PageSize = iPageSize				' Set page size
	
	If strJobType = " Any"  AND strState = " Any"  Then
		strSQL=" SELECT * FROM Job WHERE DateExpires>= Date() ORDER BY DatePosted DESC;" 
	End If 
	
	If Request(" JobType" ) <> " Any"  AND Request(" State" ) = " Any"  Then
		strSQL=" SELECT * FROM Job WHERE DateExpires>= Date() AND JobType=' "  & strJobType & " '  ORDER BY DatePosted DESC;" 
	End If
	
	If Request(" JobType" ) = " Any"  AND Request(" State" ) <> " Any"  Then
		strSQL=" SELECT * FROM Job WHERE DateExpires>= Date() AND State=' "  & strState & " '  ORDER BY DatePosted DESC;" 
	End If
	
	If Request(" JobType" ) <> " Any"  AND Request(" State" ) <> " Any"  Then
		strSQL=" SELECT * FROM Job WHERE DateExpires>= Date() AND JobType=' "  & strJobType & " '  AND State=' "  & strState & " '  ORDER BY DatePosted DESC;" 
	End If
			
	rsJob.Open strSQL, objConn
	strPageCount = rsJob.PageCount				' Get the count of the pages using the given page size
	
	If 1 > strPageCurrent Then strPageCurrent = 1
	If strPageCurrent > strPageCount Then strPageCurrent = strPageCount
	rsJob.AbsolutePage = strPageCurrent		' Move to the selected page
	
	If rsJob.EOF Then
		Response.Write " <DIV ALIGN=" " CENTER" " >Your search returned no records. Please broaden your search. <P>Also note:" &_
			" We have just released this site and are currently marketing it to prospective companies." 		
	End If
	
	If Not rsJob.EOF Then	
		Response.Write " <FONT SIZE=" " 1" "  FACE=" " VERDANA" " >Displaying Page <B>"  & strPageCurrent & " </B>"  &_
			"  of <B>"  & strPageCount & " </B></FONT><BR><BR>"  & vbCrLf	
		Response.Write " <TABLE ALIGN=" " CENTER" "  STYLE=" " BORDER-COLLAPSE: collapse" "  BORDER=" " 1" "  CELLPADDING=" " 4" "  WIDTH=" " 80%" " >" 	&_	
		" <TR><TH WIDTH=" " 40%" "  bgcolor=" " #0099CC" " ><P ALIGN=" " LEFT" " ><FONT COLOR=" " #FFFFFF" "  SIZE=" " 2" "  FACE=" " VERDANA" " >Job Title</FONT></TH>"  &_
		" 		<TH WIDTH=" " 25%" "  bgcolor=" " #0099CC" " ><FONT COLOR=" " #FFFFFF" "  SIZE=" " 2" "  FACE=" " VERDANA" " >Company</FONT></TH>"  &_
		" 		<TH WIDTH=" " 20%" "  bgcolor=" " #0099CC" " ><FONT COLOR=" " #FFFFFF" "  SIZE=" " 2" "  FACE=" " VERDANA" " >Location</FONT></TH>"  &_
		" 		<TH WIDTH=" " 15%" "  bgcolor=" " #0099CC" " ><FONT COLOR=" " #FFFFFF" "  SIZE=" " 2" "  FACE=" " VERDANA" " >Date Posted</FONT></TH>"  &_
		" 	</TR>" 
	End If
	
	Do While rsJob.AbsolutePage = strPageCurrent AND Not rsJob.EOF  
		Response.Write " <TR ALIGN=CENTER>"  &_
		" <TD P ALIGN=" " LEFT" " > " %>

<a href=" JobDetails.asp?ID=<%= rsJob(" ID" )%>"  style=" color: #0099CC" ><%=rsJob(" JobTitle" ) &" </TD>" %></a><% Response.Write " <TD> "  & rsJob(" CompanyName" ) &" </TD>"  &_
		" <TD> "  & rsJob(" State" ) &" </TD>"  &_
		" <TD> "  & rsJob(" DatePosted" ) &" </TD>"  &_
		" </TR>" 
		rsJob.MoveNext
	Loop
	Response.Write " </TABLE>" 
	
	rsJob.Close
	Set rsJob = Nothing
	
	If strPageCurrent <> 1 Then
		Response.Write " <A HREF = " " ./JobSearchResultsPaging.asp?page=" 
		Response.Write strPageCurrent -1
		Response.Write " " " >Previous Page</A>"  & vbCrLf
		Response.Write "   "  & vbCrLf
	End If
	
	If strPageCurrent < strPageCount Then
		Response.Write " <A HREF=" " ./JobSearchResultsPaging.asp?page=" 
		Response.Write strPageCurrent + 1
		Response.Write " " " >Next Page</A>"  & vbCrLf
	End If
%>


Do you have any ideas of how to fix this problem? Also, is this an okay method (" paging" ) or is there a better method I should be using? You are probably going to say the other article you referenced. If so, I will try it with that, but it seemed so complex with the little brain power I have![:D]









Spooky -> RE: Count Records and Multiple Pages (9/7/2002 17:29:12)

I think your SQL string is null

If you do this :


If strPageCurrent =2 then
Response.write strSQL
response.end
End if

rsJob.Open strSQL, objConn 


Is the SQL string correct on page 2?




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625