|
 |
asp_databases thread: list boxes and where statements
Message #1 by "Todd Moses" <t.moses@w...> on Tue, 19 Jun 2001 14:31:48
|
|
I am trying to take the "Select Case" example in "Beginning ASP 3.0" a couple of steps further.
Based on the value selected in the list box, I want that value to be the in the "where" statement for
retrieving data from a database.
For example, if I have a database of all pro sports teams, and the list box contains sport types, if the
user selects "Football", I want the resulting asp page to give me a list of all the records with "football" in
the "sport type" field.
I can do this in MS Access, but I can not figure it out in ASP. Any ideas?
Message #2 by slau@p... on Wed, 20 Jun 2001 16:27:56
|
|
Hi there,
It's based on using variables in sql statements. Here's a snippet of code
for you. I'm assuming that you have a database of data to work on already?
GRABDATA.HTML
<form method="post" action="results.asp">
<select name = mySport>
<option>Hockey
<option>Soccer
<option>Badminton
</option>
RESULTS.ASP
requestedSport = Request.Form("mySport")
WhereStr = "Sport_Field = '" & requestedSport & "'"
objRS.open select * from aTable where " &WhereStr, objConn
Hopefully the code is self-documenting enough. If not, feel free
to send me an email.
Regards,
Sandra
> I am trying to take the "Select Case" example in "Beginning ASP 3.0" a
couple of steps further.
>
> Based on the value selected in the list box, I want that value to be the
in the "where" statement for
> retrieving data from a database.
>
> For example, if I have a database of all pro sports teams, and the list
box contains sport types, if the
> user selects "Football", I want the resulting asp page to give me a list
of all the records with "football" in
> the "sport type" field.
>
Message #3 by Gee Vee <happygv@y...> on Wed, 20 Jun 2001 22:13:57 -0700 (PDT)
|
|
Hi,
Sandra's code should solve your issue, I just want to
add one more point to it. Suppose, if you are using
some Id field in the the Database that refer to the
Sports types displayed in the List box and if the
database is indexed based on that Id field, then you
can even fill the listbox by querying the database and
can use VALUE=IDFIELD_VALUE in the <Option> tag, so
that the Id will be passed with the query string to
query the database instead of sending the sport type
itself. This is just a solution to improve the
performance.
regards
Vijay.G
--- slau@p... wrote:
> Hi there,
>
> It's based on using variables in sql statements.
> Here's a snippet of code
> for you. I'm assuming that you have a database of
> data to work on already?
>
> GRABDATA.HTML
> <form method="post" action="results.asp">
>
> <select name = mySport>
> <option>Hockey
> <option>Soccer
> <option>Badminton
> </option>
>
> RESULTS.ASP
> requestedSport = Request.Form("mySport")
> WhereStr = "Sport_Field = '" & requestedSport & "'"
>
> objRS.open select * from aTable where " &WhereStr,
> objConn
>
> Hopefully the code is self-documenting enough. If
> not, feel free
> to send me an email.
> Regards,
> Sandra
>
>
> > I am trying to take the "Select Case" example in
> "Beginning ASP 3.0" a
> couple of steps further.
> >
> > Based on the value selected in the list box, I
> want that value to be the
> in the "where" statement for
> > retrieving data from a database.
> >
> > For example, if I have a database of all pro
> sports teams, and the list
> box contains sport types, if the
> > user selects "Football", I want the resulting asp
> page to give me a list
> of all the records with "football" in
> > the "sport type" field.
--------------------------------------------
Vijay Kumar. G - Web Programmer
Unimobile, Inc. - "Enterprise Wireless Data Solutions"
http://www.unimobile.com
Phone: +xx-xx-xxxxxxx Ext 115
(Personal E-Mail ID - happygv@y...)
---------------------------------------------
|
|
 |