Forums
This topic is locked
search database by "multiple selected options"
Posted 21 Jul 2002 06:54:44
1
has voted
21 Jul 2002 06:54:44 Martin Thielicke posted:
I have a search.html and a result.asp.In the search.html there is a form with
an multiple select menue like:
<select name="colors" size="4" multiple>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
You can select one or many options.
The input of the Formular will be
hand over to the result.asp by method get.
the result.asp is connected to an access.mdb
In this access_database there is a table with
the colomn eg. "my_favorite_colors"
How can I search "my_favorite_colors" by multiple
values? I think I have to split the string before.
colors=red&colors=blue&colors=green
If there is only one selected value it is very easy.
But in my case the Problem is that the user can select
one or many options and I do not know how many.
Sorry for that silly question.
Replies
Replied 21 Jul 2002 07:27:52
21 Jul 2002 07:27:52 aegis kleais replied:
Well, though you see multiple values, the variables COLOR truly holds 1 value, and that is the value of all the colors selected.
ie, if I select Green and Red and press submit, and in the results.asp page, you have:
SELECT * from table WHERE fldColor = Request.QueryString("color"
Then it should by default return all records in which the recordset's fldColor field contains red OR green.
If I'm not answering your question, please go a lil more indepth, as that I've just returned from work and am, by default, rather dense.
Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
ie, if I select Green and Red and press submit, and in the results.asp page, you have:
SELECT * from table WHERE fldColor = Request.QueryString("color"
Then it should by default return all records in which the recordset's fldColor field contains red OR green.
If I'm not answering your question, please go a lil more indepth, as that I've just returned from work and am, by default, rather dense.
Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 21 Jul 2002 10:27:52
21 Jul 2002 10:27:52 Martin Thielicke replied:
Sorry but it does not work. Maybe something is wrong with the Operator %.
<!--#include file="Connections/martina.asp" -->
<%
Dim Recordset1__suche
Recordset1__suche = "%"
if (Request.QueryString("color" <> "" then Recordset1__suche = Request.QueryString("color"
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_martina_STRING
Recordset1.Source = "SELECT * FROM tablecolor WHERE fldcolor LIKE '" + Replace(Recordset1__suche, "'", "''" + "%'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<!--#include file="Connections/martina.asp" -->
<%
Dim Recordset1__suche
Recordset1__suche = "%"
if (Request.QueryString("color" <> "" then Recordset1__suche = Request.QueryString("color"
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_martina_STRING
Recordset1.Source = "SELECT * FROM tablecolor WHERE fldcolor LIKE '" + Replace(Recordset1__suche, "'", "''" + "%'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>