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.