Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable number of variables 1

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
GB
Hi

I am currently trying to develop a little web app on our intranet where we are trying to limit use of SQL QA. So a user wants a query writing (say SELECT UserID, UserFullName, JobTitle FROM USERS WHERE JobTitle LIKE '%'+@JobTitleContains+'%' AND UserID LIKE @UserIDLike) This is stored in a table with an ID number and Title.
I then have a StoreProc that pulls all the @XXXX's out and displays them on a web page with an Input box for the variable.
Another StoredProc then reassembles the query with the variables in.

The problem I can't work out is how to pass what could be a differing number of variables back to the StoredProc. Ideally I just want it to look like:
EXEC JSP_QueryExecute 4,@JobTitleContains=Sales@UserIDLike=Jonathan Where 4 is the queryID

So in a nutshell, I am trying to get all my Request.Form data in a single string.

Please try to avoid JavaScript, I am not clever enough.....

Jonathan
 
This little snippit will take ALL the values sent over by a form and create a string separating each field with an ampersand.

Code:
str = ""
for each f in request.form
	execute "str = str & ""&" & f & "=" & request.form(f) & """"
next

'remove the starting ampersand
str = right(str,len(str) - 1)

response.write str

So if you have

HTML:
<input type="text" name="color" value="blue" />
<input type="text" name="number" value="one" />
<input type="text" name="age" value="32" />

submitting those values to the script will return a string with a value of:
Code:
color=blue&number=one&age=32

doesn't matter how many fields there are, it will take each one and build the string...

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Vicverk

I have another question, how can I exclude one form element from being included in the "str" string value. In your example above you have a text input called 'age', could that be not included in the final string? I ask because one element of my form I wish to use elsewhere.

Thanks

Jonathan
 
Vicverk

I've worked it out....
Code:
str = ""
for each f in request.form
	[COLOR=blue]if f <> ("QueryID") Then[/color]
    execute "str = str & ""&" & f & "=" & request.form(f) & """"
	[COLOR=blue]End IF[/color]
next

Thanks again...

Jonathan
 
you could also use this little snippit (which is always in my global.asp file)

Code:
function isInFilter(a,b)
blnReturn = false ' by default it's not there
ra = split(b,",")
for i = 0 to ubound(ra)
if a = ra(i) then
blnReturn = true ' it found
exit for ' don't check any futher
end if
next
isInFilter = blnReturn
end function

So:

isInFilter("red","blue,red,green") would return true
isInFilter("black","blue,red,green") would return false

In you example you could have called it as follows:

Code:
str = ""for each f in request.form    
if not isInFilter(f,"QueryID") then
execute "str = str & ""&" & f & "=" & request.form(f) & """"    
End IF
next

If you want to leave out more items, just separate each by a comma.

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top