View Full Version : multuple select drop down post to SQL
wangxx
03-07-2009, 06:04 PM
I am trying to make a page has a multiple selection drop down box, when select first names and click button, it will post the value to another ASP which is connected to an Access database, shows a table with only first names I selected.
it works when I only select 1 name. my select statement in asp is:
fp_sQry="SELECT * FROM Table1 WHERE Field1 like ::Firstname1::
it doesnt return any result when I do multiple selection.
then I changed the SQL to:
fp_sQry="SELECT * FROM Table1 WHERE Field1 in ( ::Firstname1:: )
but still no luck.
anyone have idea where i did wrong?
Thanks
Old Pedant
03-07-2009, 08:10 PM
You won't do that with just Front Page. You will have to learn how to REALLY use ASP coding.
Are you ready to do that, or do you want to continue to just use Front Page??
wangxx
03-08-2009, 05:05 AM
Thanks for your reply Old Pedant.
I know some VBA but I am really new to ASP. although i am not an IT person, I am willing learn some simple ASP coding.
I tried to just put some names in the select statement :
"SELECT * FROM Table1 WHERE Field1 in ( "sean", "susan", "john" )
it worked. just dont understand why ::Firstname1:: doesnt work.
doesnt (::Firstname1::) equal ("sean", "susan", "john" ) ?
You won't do that with just Front Page. You will have to learn how to REALLY use ASP coding.
Are you ready to do that, or do you want to continue to just use Front Page??
Old Pedant
03-08-2009, 05:49 AM
Short answer: No, it doesn't.
It *may* equal
sean, susan, john
but you can see it is missing the needed apostrophes (you should use apostrophes in SQL for text values, not quotes...you can get away with quotes in Access, but not in most DBs).
So...
I would code it as something like this:
...
<%
...
SQL = "SELECT * FROM table1 WHERE field1 IN ('" & Replace( Request("firstname1"),", ","','") & "')"
Set RS = conn.Execute( SQL )
...
%>
...
Here's an FAQ on this I wrote in ancient times:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=153
(Wow! 8 years come next month. Time sure is fun when you are having flies!)
Bullschmidt
03-09-2009, 11:59 PM
And here's a related item:
Multiple Selections
http://www.asp101.com/samples/multiple_selection.asp
wangxx
03-10-2009, 01:52 AM
thank you, guys
shakir
03-10-2009, 06:35 PM
What about this wiill play the text if the string in any place
<%
SQL = "SELECT * FROM table1 WHERE field1 like ('%" & Request("firstname1") & ' %")"
%>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.