Forums

ASP

This topic is locked

Using an Array to filter a recordset

Posted 21 May 2006 17:46:33
1
has voted
21 May 2006 17:46:33 Andy Cheshire posted:
I have a form on a page with some checkboxes (the name of each checkbox is the same). The checkboxes are retrieved from a database (Access & ASP) so there might be one or many checkboxes depending on which page the user is on. The value of the checkbox is the ID of the record.

I want the user to select whichever checkboxes they like and on the next page I want to use their selection as the WHERE clause or filter to retrieve data from another table where the ID number being passed is equal to a field in the table.

So currently someone clicks two from a possible four checkboxes and the ID numbers of the two they selected are 16 and 18. On the next page I can retrieve their selection via Request.Querystring and I get an array of 16,18. I can split that array so then I've got ID(0) = 16 and ID(1) = 18 but how do I retrieve from the database the two records whose ID is 16 and 18.

I'm not too good at writing my own recordsets I usually use the Dreamweaver recordset so I'm only used to filtering my recordsets by a single passed variable or cookie.

Sorry if I've not explained that too well, basically i need to say to the database return all records where the ID is equal to X, Y and Z (where XYZ are in an array and there might be just one ID (i.e. X) or there might be many.

Many thanks.

Replies

Replied 21 May 2006 18:11:05
21 May 2006 18:11:05 micah santos replied:
i've been dealing with this situaition. i'll work on the sample online demo for this one later.

cheers!
Replied 21 May 2006 19:32:46
21 May 2006 19:32:46 micah santos replied:
can you just post the database structure you used?
Replied 22 May 2006 12:06:41
22 May 2006 12:06:41 Andy Cheshire replied:
Someone else suggested I try SQL IN and it works a treat.

SELECT column_name FROM table_name
WHERE column_name IN (variable-array)

www.w3schools.com/sql/sql_in.asp

Thanks.

Reply to this topic