?
Solved

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

Posted on 2008-02-11
12
Medium Priority
?
613 Views
Last Modified: 2008-03-07
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
0
Comment
Question by:lshane
  • 7
  • 5
12 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20872474
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
 

Author Comment

by:lshane
ID: 20872775
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20872848
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:lshane
ID: 20880411
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
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20880605
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
 

Author Comment

by:lshane
ID: 20880672
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
 

Author Comment

by:lshane
ID: 20881227
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20881478
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
 

Author Comment

by:lshane
ID: 20926053
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
 

Author Comment

by:lshane
ID: 21067586
Sorry for the delay.  Been going crazy.  I think I can make this work.

Thanks so much,
Shane
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21068129
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
 

Author Comment

by:lshane
ID: 21075838
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question