How to create a loop for checkbox values passed from a form

DWMX
WIN XP PRO
Classic ASP VBScript
MS Access

Hello.  I have a basic search form that searches by State from a dropdown list of states (testsales.asp)

It searches a table named "sale_listings" in the db (testsearchresults.asp) and displays a repeating region of all sales in the recordset.

On the "results" page, I have a checkbox next to each sale that is displayed from the recordset.
I bound the checkbox to the "sale_ID" of the recordset.

The checkboxes are there so I can select whichever sales I want and then be sent to a Printer-Friendly page to display only the sales I checked.

Question:
How can I do this?
I used the "GET" method and I see all the "sale_ID" sales in the URL that I selected, but I get an error on the Printer-Friendly page where I just have a recordset querying for "sale_ID" in the request.queystring.

I would imagine I would need some sort of loop to loop through all "sale_ID" sales in the URL, but I'm not sure how to do that.

Here's the page for reference.  Just do a search on "GA" and you will see some sales:
<http://www.thebargainwatcher.com/testsales.asp>

Thank you so much in advance.

Shane
lshaneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b0lsc0ttIT ManagerCommented:
lshane,

For a loop try ...

var arIDs = Split(Request.Querystring("sale_ID"), ", ")
For each item in arIDs
    ' what you want to do in loop
    '    use "item" to access each value that was checked
Next

Let me know if you have any questions or need more information.

b0lsc0tt
0
lshaneAuthor Commented:
Hi, b0lsc0tt.  Thanks so much.  I am having a difficult time knowing where to place the code.

I will attach the entire code from the page (including yours).  It's only a raw, basic page, so it's not too much.

The recordset on the page is filtering for "sale_ID" in the querystring also.  I'm not sure if I have to alter that.  I'm sure you'll tell me.


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/connbargain.asp" -->
<%
Dim rsPFSales__MMColParam
rsPFSales__MMColParam = "1"
If (Request.QueryString("sale_ID") <> "") Then 
  rsPFSales__MMColParam = Request.QueryString("sale_ID")
End If
%>
<%
Dim rsPFSales
Dim rsPFSales_numRows
 
Set rsPFSales = Server.CreateObject("ADODB.Recordset")
rsPFSales.ActiveConnection = MM_connbargain_STRING
rsPFSales.Source = "SELECT * FROM sale_listings WHERE sale_ID = " + Replace(rsPFSales__MMColParam, "'", "''") + ""
rsPFSales.CursorType = 0
rsPFSales.CursorLocation = 2
rsPFSales.LockType = 1
rsPFSales.Open()
 
rsPFSales_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<%
var arIDs = Split(Request.Querystring("sale_ID"), ", ")
For each item in arIDs
  <tr>
    <td><%=(rsPFSales.Fields.Item("sale_title").Value)%></td>
  </tr>
    '    use "item" to access each value that was checked
Next
%>
 
</table>
 
</body>
</html>
<%
rsPFSales.Close()
Set rsPFSales = Nothing
%>

Open in new window

0
b0lsc0ttIT ManagerCommented:
Are you getting the results in the recordset that you need?  If so I don't see why you use the querystring results again.  They are in the recordset as the field sale_ID.

If the recordset also isn't working then you need to use IN in the SQL query.  When you are looking for results matching more than 1 sale_ID then that is the way to do it.  What type of field (in the DB) is sale_ID?

Basically the SQL would look like ...

SELECT * FROM sale_listings WHERE sale_ID IN (id1, id2, id3)

Depending on the field type (in the DB) and the DB you use you may need delimit the values in the parentheses.  You could use the split to help make this.  In some case a loop may be needed to add the delimiter so let me know the type of DB and the type of field.

Then in the html just use the recordset and its results.

Let me know how this helps or if you have a question.  If you need help with the script then please answer the things I asked.

bol
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

lshaneAuthor Commented:
Hi, b0l.  Cool - thank you.

The "sale_ID" is an "autonumber" field.
The DB is MS Access.

I tried just creating a basic recordset such as:  
SELECT * FROM sale_listings WHERE sale_ID = MMColParam

(  Where MMColParam = "request.querystring("sale_ID")"  )

Then I applied a Repeat Region to the row.

However, it did not work... probably because several "sale_ID" parameters were coming across the URL in a concatenated fashion.

The SQL you showed looks more like what I need, but I'm uncertain how to type it, or enter it; so I'll definitely need your assistance with that, please.

0
b0lsc0ttIT ManagerCommented:
Since the sale_ID field is numeric you should be able to just use ...

"SELECT * FROM sale_listings WHERE sale_ID IN (" & MMColParam & ")"

The values from Request.Querystring will come like ...

1, 2, 3, 4, 5

... which is just what we want for that IN statement.  Usually you wouldn't have the space (see http://www.w3schools.com/sql/sql_in.asp for an example) but I don't believe it will be a problem.  If it is let me know and I can give you script to do it without them.

Let me know how that works or if you have a question.

bol
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lshaneAuthor Commented:
Thank you so much, b0l.

I'll try it when I get home this evening - in 2 or 3 hours.

I'll let you know.

Thank you,
Shane
0
lshaneAuthor Commented:
Hi, b0l.  

OK, I tried it, and I continue to get errors like "Too few parameters...expected 1...".

I'm placing the following code in the SQL box in DWMX:
===================================================
SELECT *
FROM sale_listings
WHERE sale_ID IN ("& MMColParam &")
===================================================
MMColParam is equal to "request.querystring("sale_ID")".

I tried it with single quotes, no quotes, no parentheses, etc.
Still get errors.

Still needing help.
Thanks so much.
0
b0lsc0ttIT ManagerCommented:
Make sure Request.Querystring("sale_ID") has a value first.  Add something like ...

If Request.Querystring("sale_ID") = "" then
    Response.Write "There are no ids."
    Response.End
End if

That block would go before the code to use the SQL.  If you see that message then you will know there were no values to use.

If you still have a problem or question then please post your current code, including the part where you set MMColParam.

bol
0
lshaneAuthor Commented:
Hi, bol.  Sorry for the delay.  I didn't see your post come through on my E-mail.

I'll post the code tomorrow.

I was getting the "Too few parameters..." message when I pressed the "TEST" button in the SQL box of DWMX.  Typically I can just enter a default value and press "TEST" and if there are no ID's, it would just say "No Data".  This is giving me some kind of error because it thinks something is missing.

I'll study it a little more tomorrow and post the code.

Thank you SO much,
Shane
0
lshaneAuthor Commented:
Sorry for the delay.  Been going crazy.  I think I can make this work.

Thanks so much,
Shane
0
b0lsc0ttIT ManagerCommented:
Your welcome!  Thanks for the fun question, the grade and the points.  I'm glad I could help.  I'll see you around. :)

bol
0
lshaneAuthor Commented:
Hi, b0l.  I was able to get the selections to appear on the Printer-Friendly page after selecting the checkboxes, but now I'm having issues with getting them to separate, as opposed to being in a row.

The following is my objective layout:

Sale Title
Start Date - End Date
Driving Directions
<HR>

I will post this to another thread, but I wanted to give you a heads-up, if you wanted to try and assist me.  Thanks so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.