|
 |
asp_databases thread: Simple? Get multiple records based on list of id's...
Message #1 by "Matt Snider" <finn@s...> on Thu, 28 Feb 2002 00:29:31
|
|
I am trying to get a selection of multiple records from a table based on
row ID. I'm using checkboxes in a form, each having a unique value of an
ID in this table. A visitor can select one or more of these checkboxes.
I want the recordset to be only these specified records.
Simple enough? I think I am having a bad day and making this more
difficult than it should be.
I want to be able to do something like:
SELECT * FROM Table WHERE id = " & Request.Form("checkboxID") & ";"
But the Request.Form("checkboxID") may
be "1,4,5,66,212,436,1003,4005,5677" And I want only to pull these 9
records. In some scenarios, we may need to get dozens or hundreds of
records.
What is the fastest way to do this?
Any help for a struggling newbie?
Thanks,
Matt
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 28 Feb 2002 12:01:56 +1100
|
|
<%
' Validate all your data here
' Now, if the IDs are valid, let's get records
If Request.Form("chkID").Count > 0 then
strIDs = Request.Form("chkID")
strSQL = _
"SELECT field1, field2, field " & _
"FROM table1 " & _
"WHERE tableID IN (" & strIDs & ")"
arrResults = ArrayFromSQL(objConn, strSQL)
End If
%>
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Matt Snider" <finn@s...>
Subject: [asp_databases] Simple? Get multiple records based on list of
id's...
: I am trying to get a selection of multiple records from a table based on
: row ID. I'm using checkboxes in a form, each having a unique value of an
: ID in this table. A visitor can select one or more of these checkboxes.
: I want the recordset to be only these specified records.
:
: Simple enough? I think I am having a bad day and making this more
: difficult than it should be.
:
: I want to be able to do something like:
:
: SELECT * FROM Table WHERE id = " & Request.Form("checkboxID") & ";"
:
: But the Request.Form("checkboxID") may
: be "1,4,5,66,212,436,1003,4005,5677" And I want only to pull these 9
: records. In some scenarios, we may need to get dozens or hundreds of
: records.
:
: What is the fastest way to do this?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #3 by "Drew, Ron" <RDrew@B...> on Wed, 27 Feb 2002 21:03:00 -0500
|
|
SELECT * FROM Table WHERE id in (" & Request.Form("checkboxID") & ");"
-----Original Message-----
From: Matt Snider [mailto:finn@s...]
Sent: Wednesday, February 27, 2002 7:30 PM
To: ASP Databases
Subject: [asp_databases] Simple? Get multiple records based on list of
id's...
I am trying to get a selection of multiple records from a table based on
row ID. I'm using checkboxes in a form, each having a unique value of
an
ID in this table. A visitor can select one or more of these checkboxes.
I want the recordset to be only these specified records.
Simple enough? I think I am having a bad day and making this more
difficult than it should be.
I want to be able to do something like:
SELECT * FROM Table WHERE id =3D " & Request.Form("checkboxID") & ";"
But the Request.Form("checkboxID") may
be "1,4,5,66,212,436,1003,4005,5677" And I want only to pull these 9
records. In some scenarios, we may need to get dozens or hundreds of
records.
What is the fastest way to do this?
Any help for a struggling newbie?
Thanks,
Matt
$subst('Email.Unsub').
Message #4 by "Muskie" <finn@s...> on Thu, 28 Feb 2002 16:21:39
|
|
Thanks! That works like a gem... I've never used the In operator before,
but now after reading into it's uses it will make a lot more things easier.
Matt
|
|
 |