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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to pass records from paged recordset? 3

Status
Not open for further replies.

Cirrus9

IS-IT--Management
Aug 21, 2001
248
US
I am hoping that one (or more) of you can help me with my approach to the following task:

*Allow users to order product samples online*

1)I have about 150 product records that are returned in a paged recordset. Each record is unique.

2)Have a checkbox available for each product record so that a user can select to have a sample(s) sent for every product selected.

3)I will pass the selected records by form.

4)I need the user to be able to add or remove the samples they choose to a list (shopping cart style) for final review or edit.

Is it best method to use a cookie or session object? How should I go about it? I'm looking for direction to generate the cleanest method. I should be ok to put the code together if I can get a recommendation.

Any help you can offer will be greatly appreciated. Thanks in advance!
 
Why not just pass the product ID along in your various forms.. use "hidden" elements if necessary.

PS: Sessions use cookies.
 
Thats what I did first. The problem I ran into is that when I used a form with hidden values, whenever I paged through the set, it lost all of the selections I had made for the previous page. This is where I thought the cookies would make sense. If I use cookies:

What method should use to write to the cookie? Onclick event using a text-link or use a checkbox?

What you are saying is how I originally approached it, I thought I might have been going about it the wrong way when I ran into the checkbox problem.

Thanks for your help
 
Cirrus9 said:
The problem I ran into is that when I used a form with hidden values, whenever I paged through the set, it lost all of the selections I had made for the previous page.

can you show us the code for this...because i am sure that we can pass the value without losing it...

-DNG
 
I don't have accessto the server that has the script right now. I was testing locally and I am there right now with no access from the outside.

I am thinking that my mistake was somwhere in the way I had it set up. I had a standard paged recordset with the records l;ooping through the form. I had the submit button at the end of the form and passed the form to a page that did response.write to verify that the variable had passed.

I tested the form with a static value for testing and it worked.I tested the paged recordset outside of the form and it worked. It just wouldn't pass the value with the paged recordset.

I know that you can't really help me troubleshoot without seeing the code but I have written forms a hundred times and had no problems until I had to embed a paged recordset. I know it is probably something simple I have overlooked (it seems like it always is).

I even started to embed an array and go a different way with it but it really seems that it shouldn't be that difficult of a task. I will post my code as soon as I get it. I think I may have saved a copy on disk and I will post if I did.

Thanks again....
 
This is the origination page for the paged recordset

<% Dim StrConn,strSQL

StrConn = "DSN=carpet1"
Set conn = server.createobject("adodb.connection")
conn.Open StrConn
Set strSQL = conn.Execute("Select * from tbl_prdtimages INNER JOIN tbl_products on tbl_prdtimages.prdctimage_productID=tbl_products.product_ID WHERE prdctImage_ImgTypeID =1")

If strSQL.EOF Then %>
<table cellspacing=1 border=0 cellpadding=2 width="100%">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" arial"" size="3">Sorry, no records were found. </font><font face="Arial, Helvetica, sans-serif"></font>
</td>
</tr>
</table>
<%
ElseIf request("begin") = "" Then
begin = 1
Else
begin = Cint(request("begin"))
End If

tot = ((begin+pagetot)-1)

If tot > strSQL.RecordCount Then
tot = strSQL.RecordCount
End If

i = 1
navi = ""
For j = 1 to strSQL.RecordCount step pagetot
If j <> 1 Then navi = navi & " | "
If j = Cint(begin) Then
navi = navi & "<b>"&i&"</b>"
Else
navi = navi & "<a href="""
navi = navi & Request.ServerVariables("url") & "?begin=" & j & "&which=" & tbl
navi = navi & """>"
navi = navi & i & "</a>"
End If
i = i + 1
Next
i = 1
strSQL.Move begin - 1
%>
<Form action="sample_send.asp" Method="POST" Name="SAMPULL">
<Table width="500" align="left">
<Tr>
<% For x = begin to begin + (pagetot - 1)
If strSQL.EOF Then exit For%>
<tr>
<td align="left">
<Input type="checkbox" name="Product_Name" value="<%response.write strSql("product_MerchantProductID")%>">&nbsp;<IMG SRC="<%response.write strSql("prdctimage_FileName")%>">&nbsp;
<Font face="Arial, Helvetica, sans-serif" size="1" color="#000000"><%response.write strSQL("product_Name")%><br><%response.write strSQL("product_shortdescription")%></Font>
<br>
</td>
<%
i = i + 1
strSQL.MoveNext
Next
%>
</tr>
<tr>
<td><Input Type="Submit" name="Submit" value="Order">
</FORM></td>
</tr>
</table>
<table cellspacing="2" cellpadding="2" width=100%>
<tr>
<td align=right>
<font face="Arial, Helvetica, sans-serif" size="2">
<b>&nbsp;<%=begin%>&nbsp;-&nbsp;<%=tot%>&nbsp;of&nbsp;<%=strSQL.RecordCount%>&nbsp;Page:</b>&nbsp;<%=navi%></font>
</td>
</tr>
</table>
<%
strSQL.Close
Set strSQL = nothing
Conn.close
Set Conn = Nothing
Set StrConn = Nothing
%>


I can't find the original results page but it was a basic response.write statement that was something like this

<% response.write request.form strSql("Product_name")%><br>



Like I said, it is probably something simple or obvious that I am overlooking. Thanks again for taking the time to help me out.

 
easiest way i've dealt with this before is, if the only pertainant "object" on the page is the checkboxes, not qty boxes, or any other special form elements, you make the whole page a form, name all the chackboxes the same, with different values ( not true/false, but value="prodID" ), since all these checkboxes are named the same, they will become comma delimited under the same form element name, you just request this form element name in the next page (passed along with the page number etc) do a simple split/parse on the comma delimited values as you display records to mark the checkbox checked by default or not, and take your prior checkbox value you parsed, making it's value be a hidden form element under the same name, then additional checkboxes checked will as well be added or removed.

the only major issue with this is if you move to a prior page and check or uncheck more boxes, they wont get removed automatically from the list, you may want a small JS handler for the hidden form element value

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005
 
Thanks for taking the itme to help....... I got it working the way I needed it to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top