Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set querystring to session?

Status
Not open for further replies.

danieljoo

MIS
Oct 9, 2002
43
0
0
US
Lots of reading, answer might not be that hard...I am currently working on a set of asp pages that allows my company to keep track of vendors that are attending our meetings. The default asp page allows the user to either go directly to a:

1. link that displays all individual vendors names(vendorind.asp)
or
2. link that displays all vendor companies (vendorcomp.asp)

From vendorcomp.asp the user can select a link next to each vendor company name that will send them to the vendorind.asp displaying only thier individual vendor names. This is done by sending a querystring with the vendors company number (ex. vendormeetings/vendors/vendorind.asp?VendorNumber=302).

The page vendorind.asp displays 20 records by Vendor company. Each record contains the following: ID, VendorNumber, FirstName, LastName. Each field can be sorted and also searched on using a basic search (type in what you are looking for, it searches all fields). The problem I am having is that when I pass VendorNumber to Vendorind using the querystring and more than 20 records are returned and the user selects the next link (or a page number link), the original querystring with the VendorNumber is not passed. I am not sure how to set this up (do I set the querystring as a session, are there issues by doing this?). Here is the code:

<% 'no security checking %>
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader &quot;pragma&quot;, &quot;no-cache&quot;
Response.addHeader &quot;cache-control&quot;, &quot;private&quot;
Response.CacheControl = &quot;no-cache&quot;
%>
<!--#include file=&quot;db.asp&quot;-->

<%
displayRecs = 20
recRange = 10
%>

<%
' Get table name
tablename = &quot;[vendorind]&quot;
dbwhere = &quot;&quot;
b_search = &quot;&quot;
%>



<%
' Get search criteria for basic search
pSearch = Request.QueryString(&quot;psearch&quot;)
If pSearch <> &quot;&quot; Then
pSearch = replace(pSearch,&quot;'&quot;,&quot;''&quot;)
pSearch = replace(pSearch,&quot;[&quot;,&quot;[[]&quot;)
b_search = b_search & &quot;[VendorNumber] LIKE '%&quot; & pSearch & &quot;%' OR &quot;
b_search = b_search & &quot;[FirstName] LIKE '%&quot; & pSearch & &quot;%' OR &quot;
b_search = b_search & &quot;[LastName] LIKE '%&quot; & pSearch & &quot;%' OR &quot;
End If
If len(b_search) > 4 Then
b_search = mid(b_search,1,len(b_search)-4)
b_search = &quot;(&quot; & b_search & &quot;)&quot;
End If
%>



<%
'Build search criteria
If b_search <> &quot;&quot; Then
dbwhere = dbwhere & b_search 'basic search
End If

'Save search criteria
If dbwhere <> &quot;&quot; Then
Session(&quot;tablename&quot;) = tablename
Session(&quot;dbwhere&quot;) = dbwhere
'reset start record counter
startRec = 1
Session(&quot;vendorind_REC&quot;) = startRec
Else
If tablename = Session(&quot;tablename&quot;) Then
dbwhere = Session(&quot;dbwhere&quot;)
Else
'reset search criteria
dbwhere = &quot;&quot;
Session(&quot;dbwhere&quot;) = dbwhere
End If
End If

'Get clear search cmd
If Request.QueryString(&quot;cmd&quot;).Count > 0 then
cmd=Request.QueryString(&quot;cmd&quot;)
If ucase(cmd) = &quot;RESET&quot; Then
'reset search criteria
dbwhere = &quot;&quot;
Session(&quot;dbwhere&quot;) = dbwhere
End If
End If

%>


<%
' Load Default Order
DefaultOrder = &quot;&quot;
DefaultOrderType = &quot;&quot;

' Check for an Order parameter
OrderBy = &quot;&quot;
If Request.QueryString(&quot;order&quot;).Count > 0 Then
OrderBy = Request.QueryString(&quot;order&quot;)
' Check if an ASC/DESC toggle is required
If Session(&quot;vendorind_OB&quot;) = OrderBy Then
If Session(&quot;vendorind_OT&quot;) = &quot;ASC&quot; Then
Session(&quot;vendorind_OT&quot;) = &quot;DESC&quot;
Else
Session(&quot;vendorind_OT&quot;) = &quot;ASC&quot;
End if
Else
Session(&quot;vendorind_OT&quot;) = &quot;ASC&quot;
End If
Session(&quot;vendorind_OB&quot;) = OrderBy
Session(&quot;vendorind_REC&quot;) = 1
Else
OrderBy = Session(&quot;vendorind_OB&quot;)
if OrderBy = &quot;&quot; then
OrderBy = DefaultOrder
Session(&quot;vendorind_OB&quot;) = OrderBy
Session(&quot;vendorind_OT&quot;) = DefaultOrderType
End If
End If

' Check for a START parameter
If Request.QueryString(&quot;start&quot;).Count > 0 Then
startRec = Request.QueryString(&quot;start&quot;)
Session(&quot;vendorind_REC&quot;) = startRec
Else
startRec = Session(&quot;vendorind_REC&quot;)
if not isnumeric(startRec) or startRec = &quot;&quot; then
'reset start record counter
startRec = 1
Session(&quot;vendorind_REC&quot;) = startRec
End If
End If

' Open Connection to the database
set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open xDb_Conn_Str


'If there is a vendornum in the string
If Request.Querystring(&quot;VendorNumber&quot;)<> &quot;&quot; then
myVar1=Request.Querystring(&quot;VendorNumber&quot;)
strsql = &quot;select * from [vendorind] where VendorNumber =&quot;&myVar1&&quot;&quot;
If dbwhere <> &quot;&quot; Then
strsql = strsql & &quot; WHERE &quot; & dbwhere
End If
If OrderBy <> &quot;&quot; then
strsql = strsql & &quot; ORDER BY [&quot; & OrderBy & &quot;] &quot;& Session(&quot;vendorind_OT&quot;)
End if
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open strsql, conn, 1, 2
totalRecs = rs.RecordCount
'If there is no vendornum in the string
else
strsql = &quot;select * from [vendorind]&quot;
If dbwhere <> &quot;&quot; Then
strsql = strsql & &quot; WHERE &quot; & dbwhere
End If
If OrderBy <> &quot;&quot; then
strsql = strsql & &quot; ORDER BY [&quot; & OrderBy & &quot;] &quot;& Session(&quot;vendorind_OT&quot;)
End if
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open strsql, conn, 1, 2
totalRecs = rs.RecordCount
End If
%>

<!--#include file=&quot;header.asp&quot;-->

<p><font size=&quot;-1&quot;>TABLE : vendorind</font></p>
<form action=&quot;vendorindlist.asp&quot;>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>
<tr>
<td><font size=&quot;-1&quot;>Quick Search (*)</font></td>
<td>
<input type=&quot;Text&quot; name=&quot;psearch&quot; size=10>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;GO!&quot;>
</td>
<td><a href=&quot;vendorindind.asp?cmd=reset&quot;><font size=&quot;-1&quot;>Show All</font></a></td>
</tr>
</table>
</form>


<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>

<tr>
<td>
<font size=&quot;-1&quot;><a href=&quot;VendorComp.asp&quot;>Back to Company List</font></a>
</td>
</tr>
</table>
<p>


<form name=&quot;vendorindlist&quot;>
<table border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;5&quot; bgcolor=&quot;#CCCCCC&quot;>
<tr bgcolor=&quot;#0099CC&quot;>
<td>
<a href=&quot;vendorindlist.asp?order=<%= Server.URLEncode(&quot;ID&quot;) %>&quot;><font color=&quot;#FFFFFF&quot;><font size=&quot;-1&quot;>ID </font></font></a>
</td>
<td>
<a href=&quot;vendorindlist.asp?order=<%= Server.URLEncode(&quot;VendorNumber&quot;) %>&quot;><font color=&quot;#FFFFFF&quot;><font size=&quot;-1&quot;>Vendor Number (*)</font></font></a>
</td>
<td>
<a href=&quot;vendorindlist.asp?order=<%= Server.URLEncode(&quot;CustomerName&quot;) %>&quot;><font color=&quot;#FFFFFF&quot;><font size=&quot;-1&quot;>First Name (*)</font></font></a>
</td>
<td>
<a href=&quot;vendorindlist.asp?order=<%= Server.URLEncode(&quot;CustomerName&quot;) %>&quot;><font color=&quot;#FFFFFF&quot;><font size=&quot;-1&quot;>Last Name (*)</font></font></a>
</td>
<td> </td>
<td> </td>
</tr>


<%
'Avoid starting record > total records
if clng(startRec) > clng(totalRecs) then
startRec = totalRecs
end if
'Set the last record to display
stopRec = startRec + displayRecs - 1

'Move to first record directly for performance reason
recCount = startRec - 1
if not rs.eof then
rs.movefirst
rs.move startRec - 1
end if

recActual = 0
Do While (NOT rs.EOF) AND (recCount < stopRec)
recCount = recCount + 1
If Clng(recCount) >= Clng(startRec) Then
recActual = recActual + 1 %>

<%
'set row color
bgcolor=&quot;#FFFFFF&quot;
%>

<%
' Display alternate color for rows
If recCount mod 2 <> 0 Then
bgcolor=&quot;#F5F5F5&quot;
End If
%>

<%
x_ID = rs(&quot;ID&quot;)
x_VendorNumber = rs(&quot;VendorNumber&quot;)
x_FirstName = rs(&quot;FirstName&quot;)
x_LastName = rs(&quot;LastName&quot;)

%>
<tr bgcolor=&quot;<%= bgcolor %>&quot;>
<td><font size=&quot;-1&quot;>
<% response.write ucase(x_ID) %> 
</font></td>
<td><font size=&quot;-1&quot;>
<% response.write x_VendorNumber %> 
</font></td>
<td><font size=&quot;-1&quot;>
<% response.write ucase(x_FirstName) %> 
</font></td>
<td><font size=&quot;-1&quot;>
<% response.write ucase(x_LastName) %> 
</font></td>

<%
end if
rs.MoveNext
Loop
%>

</tr>
</table>
</form>
<%
if totalRecs > 0 then

' Find out if there should be Backward or Forward Buttons on the table.
If startRec = 1 Then
isPrev = False
Else
isPrev = True
PrevStart = startRec - displayRecs
If PrevStart < 1 Then PrevStart = 1 %>
<hr size=&quot;1&quot;>
<strong><a href=&quot;vendorindlist.asp?start=<%=PrevStart%>&quot;><font size=&quot;-1&quot;>[<< Prev]</font></a></strong>
<%
End If

' Display Page numbers
If (isPrev OR (NOT rs.EOF)) Then
If (NOT isPrev) Then Response.Write &quot;<HR SIZE=1>&quot;
x = 1
y = 1

dx1 = ((startRec-1)\(displayRecs*recRange))*displayRecs*recRange+1
dy1 = ((startRec-1)\(displayRecs*recRange))*recRange+1
If (dx1+displayRecs*recRange-1) > totalRecs then
dx2 = (totalRecs\displayRecs)*displayRecs+1
dy2 = (totalRecs\displayRecs)+1
Else
dx2 = dx1+displayRecs*recRange-1
dy2 = dy1+recRange-1
End If

While x <= totalrecs
If x >= dx1 and x <= dx2 Then
If Clng(startRec) = Clng(x) Then %>
<strong><font size=&quot;-1&quot;><%=y%></font></strong>
<% Else %>
<strong><a href=&quot;vendorindlist.asp?start=<%=x%>&quot;><font size=&quot;-1&quot;><%=y%></font></A></strong>
<% End If
x = x + displayRecs
y = y + 1
elseif x >= (dx1-displayRecs*recRange) and x <= (dx2+displayRecs*recRange) then
if x+recRange*displayRecs < totalRecs then %>
<strong><a href=&quot;vendorindlist.asp?start=<%=x%>&quot;><font size=&quot;-1&quot;><%=y%>-<%=y+recRange-1%></font></a></strong>
<% else
ny=(totalRecs-1)\displayRecs+1
if ny = y then %>
<strong><a href=&quot;vendorindlist.asp?start=<%=x%>&quot;><font size=&quot;-1&quot;><%=y%></font></a></strong>
<% else %>
<strong><a href=&quot;vendorindlist.asp?start=<%=x%>&quot;><font size=&quot;-1&quot;><%=y%>-<%=ny%></font></a></strong>
<% end if
end if
x=x+recRange*displayRecs
y=y+recRange
else
x=x+recRange*displayRecs
y=y+recRange
End If
Wend
End If

' Next link
If NOT rs.EOF Then
NextStart = startRec + displayRecs
isMore = True %>
<strong><a href=&quot;vendorindlist.asp?start=<%=NextStart%>&quot;><font size=&quot;-1&quot;>[Next >>]</font></a></strong>
<% Else
isMore = False
End If %>
<hr size=&quot;1&quot;>
<% If stopRec > recCount Then stopRec = recCount %>
<font size=&quot;-1&quot;>Records <%= startRec %> to <%= stopRec %> of <%= totalRecs %></font>

<% Else %>
<br><br>
<font size=&quot;-1&quot;>No records found!</font>
<br><br>
<% End If %><%
' Close recordset and connection
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing %><!--#include file=&quot;footer.asp&quot;-->
 
Try
Session(&quot;Ven_Num&quot;) = Requset.Querystring(&quot;VendorNumber&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top