WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-15-2004, 09:05 AM
WebProWorld Member
 

Join Date: Jun 2004
Location: Charlotte, NC
Posts: 58
ken71683 RepRank 0
Default Very New to ASP need help!!!

I just started playing around with ASP and database stuff, I've never worked with either before. My question is this:

I have a page that loops all the records in my little test database and displays them over three pages. But I can only get them to loop vertically. When I try to write the code to get them to loop horizontally (3 records across then move to next row) it works fine expect for this - The first page displays records 1-8 the second page displays records 4-8 and the third page displays records 7-8.

When I remove the code to loop horizontally it works fine page one (records 1-3) page two (records 4-6) page three (7-8).

What would cause this?

I know it might be something simple but remember I'm very new to this stuff and am trying to teach myself so I probably missed something.

I appreciate any help, thanks.
__________________
Ken
Reply With Quote
  #2 (permalink)  
Old 07-15-2004, 09:58 AM
paulhiles's Avatar
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: UK
Posts: 2,803
paulhiles RepRank 0
Default

A code snippet would certainly help Ken. Sounds to me as though you have both code instructions for horizontal and vertical distribution of your recordset.
Personally, I would keep the 'horizontal' part which is populating data in table cells row by row.
It doesn't matter if you end up with one long page with lots of rows... then you should introduce a 'paging' element into your code. Set a variable for the maximum number of rows returned per page.. once this limit is reached a new page is then started. There are loads of examples of this sort of technique. Let me know if you have trouble finding a suitable sample.
Reply With Quote
  #3 (permalink)  
Old 07-15-2004, 11:32 AM
WebProWorld Member
 

Join Date: Jun 2004
Location: Charlotte, NC
Posts: 58
ken71683 RepRank 0
Default

Thank you for the reply, please understand that I got the codes to do this stuff off of different tutorials and have spliced them together so it's probably a mess.

Here is the complete code to the page:

http://www.burkechristiantours.com/t...ur_results.txt

Change to ".asp" to see the page. Select "Motorcoach Tours" from the form box to see what it's doing.

I haven't fully layed out how I want this section to look so it's a mess. It's just a testing page for me.

Note: All I need to display is a picture and the name of each tour (188 motorcoach tours in real database) Having a tour per row is okay for me but our customers may get annoyed going through 30 pages of tours when I could reduce it to about 5 or 6 this way. Each of our tours are as important as the next so I wouldn't want the tours on the last pages to be unseen because a customer didn't want to go all the way to page 30.

Thank you for any help
__________________
Ken
Reply With Quote
  #4 (permalink)  
Old 07-16-2004, 12:47 AM
ADAM Web Design's Avatar
WebProWorld 1,000+ Club
 

Join Date: Dec 2003
Location: Toronto, Ontario, Canada
Posts: 2,217
ADAM Web Design RepRank 0
Default

A few corrections:
Code:
if request.querystring <> "" then
should be
Code:
if request.querystring ("type") <> "" then
Always identify your querystring name so that your script knows what to pull.

Next, your query:
Code:
		SQL = "SELECT tblTours.* FROM tblTours "
		SQL = SQL & "WHERE TourType='"& ttype & "' "
		SQL = SQL & "ORDER BY [TourName]"
Try not to use * for retrieving fields. It's heavier in terms of resource on your ASP page. Always list the fields you want, and only the fields you want. Even if you want all of the fields in a table (which in 99% of cases isn't true), this is still more efficient.

Also, the query's the same regardless of the case, so you can have the query defined after the case. The only thing that varies is the "ttype", which gets assigned in the case statement.

As far as your horizontal paging issue is concerned, I can't really follow your code (it looks like you've got way too much going on), but I can propose adding four variables that traditionally make my life a lot simpler for recordset paging purposes:

Start_record (the value associated with the position of the first record in the page)
End_record (the value associated with the position of the last record in the page)
Records_Per_page (the number of records in a page)
Record_Count (the number of records in a recordset).

So in your case, this:
Code:
Dim rs
	Set rs = Server.CreateObject("ADODB.Recordset")

		
	rs.PageSize = 3
	rs.CacheSize = 1
	rs.CursorLocation = adUseClient
		
	rs.Open SQL, connStr, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
		
		
	If Len(Request("pagenum")) = 0  Then
		rs.AbsolutePage = 1
	Else
		If CInt(Request("pagenum")) <= rs.PageCount Then
			rs.AbsolutePage = Request("pagenum")
		Else
			rs.AbsolutePage = 1
		End If
	End If
		
Dim abspage, pagecnt
	abspage = rs.AbsolutePage
	pagecnt = rs.PageCount
	pagenum = rs.pagenum
Would be replaced with...
Code:
Dim rs, Records_Per_Page, Start_record, End_record, Record_Count
	
Set rs = Server.CreateObject("ADODB.Recordset")

		
	rs.Open SQL, connStr, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
        Record_Count = RS.Recordcount ' Counts the results
	Records_Per_Page = 3	
	rs.PageSize = Records_Per_Page
	rs.CacheSize = Records_Per_Page ' this generally doesn't take up much server resource and can greatly improve the speed of execution of an ASP script
	rs.CursorLocation = adUseClient
		
		
	If Len(Request("pagenum")) = 0  Then
		rs.AbsolutePage = 1
	Else
		If CInt(Request("pagenum")) <= rs.PageCount Then
			rs.AbsolutePage = Request("pagenum")
		Else
			rs.AbsolutePage = 1
		End If
	End If
	Start_Record = RS.AbsolutePosition ' this gets the position of the first record in the current page of the recordset
        End_Record = Start_Record + Records_Per_Page - 1
        ' Make sure End_Record <= Record_Count to avoid any EOF errors.
        if End_Record > Record_Count then
                End_Record = Record_Count
        end if
After this, all you need to do to get stuff to display horizontally in a page is something like this:
Code:
<table width="100%">
<tr>
<%
     for i = Start_record to End_Record ' This will display only those records in the positions you want (e.g. on page 1, 1-3, page 2 4-6, page 3 7-8)
%>
<td width="33%">

'  This is where you put your code to display your output.  I'm not exactly sure which code that is.

</td>
<%
RS.MoveNext ' to move to the next record.
Next
%>
</tr>
</table>
There are many other things you can do to speed up and optimize your code after this, but this should get you semi-going.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0