PDA

View Full Version : puzzled with sql, asp, html form prop.......


[TvR] -=CyRuS=-
11-01-2001, 14:58
Hi all,
I am setting up a page using MS active server pages to view and query details in a database. ( for fun of course :) for uni really)
This consists of two pages, first a html form with checkboxes to allow multiple options to be checked and posted to the asp page to decide upon which sql statement to use to display the records. ( i have four options, with a possible 15 statements being the individual checkboxes and all combinations. )

The problem being, the way i am interpretating and receiving the data from the form,
Ie for a single value, ie a text box, i store the value in a var in the asp page for use in the sql statement.
but how do i use this multiple value that i receive..

The value is in the format if i use a mailto link

age=1&cash=1&delivery=1&points=1

for all four checkboxes and like

cash=1&delivery=1&points=1
delivery=1&points=1

etc.
So i could just use a big if statement in the form of (store the value in a variable within the asp results page say vartext and use an if statement to choose the sql statement (say sqlchoiceX for pseudo code variables holding sql statements) to be used in the query?

ie.
if vartext = "age=1&cash=1&delivery=1&points=1"
THEN sqlstatement = sqlchoice1
else
if vartext = "age=1&cash=1&delivery=1"
THEN sqlstatement = sqlchoice2
else
etc..... for all 15 options or is there way for me to do this????????? and send the info for all four checkboxes to the asp page (i know how to receive for single form entites using Request.Form in the asp)

It would be possible for me to receive all four check box values to independant variables and concanate the results for comparison but the scope for errors seems enormous. :bigcry: imagine null values etc.... :{

I am sure the ever helpful Microsoft :cheese: have provided us with a better way to acheive this... its just i dont know what it is. (only started ASP week or so ago)

Thx for replies in advance...

Marcus aka [TvR]-=CyRuS=- (TVR Half-Life DM clan) :pimp:

icq = 74712177 email = marcus.j.miller@talk21.com

[TvR] -=CyRuS=-
11-01-2001, 15:51
Managed to do this by changing the passed values from the text box to text strings and concatenating the results to form a comparison string to use in later 'if' statement to select sql statement to be used in the query.

This is the code, if anyone knows a better way id appreciate knowing... :)

<%
'this is the response page
varAge = Request.Form("age")
varCash = Request.Form("Cash")
varDel = Request.Form("Delivery")
varPoints = Request.Form("Points")
'This is building the string to be used in the sql query
If varAge = "age" Then
varCompString = "age"
End if
IF varCash = "cash" Then
varCompString = varCompString & "cash"
End if
If varDel = "del" Then
varCompString = varCompString & "del"
End if
If varPoints = "points" Then
varCompString = varCompString & "points"
End if
'Response.Write varCompString 'ensure correct searchstring during development

%>

Just posted this to save anyone the effort of helping when i had sorted it.. cheers anyway.
P.S. anyone know any good free asp sites?????

[PAR]DI55
11-01-2001, 21:20
How you use the info on the page you post it to depends on what form method you use. In your case, you are using a link that mimics what would happen if you were to use method="get" in the form html.

If you want to specify that you are after the info from the URL query string (the stuff atfer the "?") you use:

Request.QueryString("age")

If you use method="post" in the form html you specify by using:

Request.Form("age")

Using the two is possible if you send information like this:

action="blah.asp?blah1=1&blah2=2" method="post"

in part of the form HTML.

If you are only using one method as it would appear from your code, you can simply use:

Request("age")

ASP defaults to whatever it finds so you don't have to specify at all :)

Erm... I'll go away now :E

[TvR] -=CyRuS=-
11-01-2001, 21:40
I am using more four checkboxes and may have any permutation, all four or just one.
any ideas, peeps, its workin for now......

[PAR]DI55
15-01-2001, 20:46
I've done stuff for a site that uses three drop-down menus (<SELECT> form tags) that may or may not be used. When submitted, I first look at what was sent and dynamically build the SQL statement from that.

Here's what the code looks like for building the string:

strSQL = "SELECT * FROM AllMembers WHERE "
If Request.QueryString("ListingType") <> "All" Then
strSQL = strSQL + "ListingType = '" & Request.QueryString("ListingType") & "'"
If Request.QueryString("Area") <> "All" Or Request.QueryString("ListType") <> "Free" Then
strSQL = strSQL + " AND "
End If
End If
If Request.QueryString("Area") <> "All" Then
strSQL = strSQL + "Area = '" & Request.QueryString("Area") & "'"
If Request.QueryString("ListType") <> "Free" Then
strSQL = strSQL + " AND "
End If
End If
If Request.QueryString("ListType") = "Priority" Then
strSQL = strSQL + "Priority = 1"
End If
If Request.QueryString("ListType") = "Profile" Then
strSQL = strSQL + "WebLink LIKE 'http://www.alivenetwork.com/business_profiles/%'"
End If
If Request.QueryString("ListingType") <> "All" Or Request.QueryString("Area") <> "All" Or Request.QueryString("ListType") <> "Free" Then
strSQL = strSQL + " AND "
End If
strSQL = strSQL + "PublishInfo = 1"
strSQL = strSQL + " ORDER BY Priority Desc, CompanyName"

I hope that's the kind of idea you had in mind :)

Bandito
16-01-2001, 07:25
guuuuuuuuuuuuuuuude DissDiss :)

:monkee: