Forums

ASP

This topic is locked

sql select statement based on menu list

Posted 27 Feb 2007 21:10:54
1
has voted
27 Feb 2007 21:10:54 Barb Smith posted:
I have a menu list where the user can choose as many selections as they choose. How do I write a sql statement to show records based on the selections in the menu list? I have to think there is a simpler way than writing if/thens for 16 different options.

Thanks!
Barb
<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>


<pre id=code><font face=courier size=2 id=code>strSQL = "select * from guests where initials = '" & Session("UID" & "' and show = '1' " & dtRange & " order by " & sortField & ""
</font id=code></pre id=code>

Replies

Replied 02 Mar 2007 15:35:39
02 Mar 2007 15:35:39 Jonathan Barbeau replied:
So you would like a menu to be filled based on the selection of another select?

or

You are filtering the results of one select menu with another? I think I have been trying to figure this one out myself. Maybe we can help one another.
Replied 02 Mar 2007 23:53:33
02 Mar 2007 23:53:33 Barb Smith replied:
I finally got it. I did a loop for the index of each select option. Otherwise the form field just separates each
select value with a comma.

If this is what you're interested in I can put the code in here later. I don't have it right now. Let me know.

-Barb

Replied 05 Mar 2007 13:43:06
05 Mar 2007 13:43:06 Lee Diggins replied:
Hi Barb

If the list of data returned from your multiple menu selection is a list of integers you could use the IN operator in the WHERE clause:

WHERE columnName IN (1,2,3,4,5,6)

If it's meant to be string values you could do a find/replace on the comma's "," with single quote/comma/single quote "','" then add a single quote at the beginning and end of your values, it'll look like this then:

WHERE columnName IN ('1','2','3','4','5','6')

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 27 Mar 2007 18:47:13
27 Mar 2007 18:47:13 zafarana gisondi replied:
I am tryiugn to do something similar.. was wondering if you could post some sample code up? I have a dynamic drop down and based on that my dynamic table needs to be updated. This is in javascript.

Reply to this topic