...

View Full Version : Complicated search form



BarrMan
02-23-2006, 11:28 AM
I made a search form and i want the page that the form lead to, to check if fields are empty.
this was the easy part, the harder part is to do an sql statement which takes only the non empty fields of the form and searches for them.

is there any other way to do that other than making a big if statements and insert every small detail to it?

thanks in advanced.

SpirtOfGrandeur
02-23-2006, 11:49 AM
Easy answer nope. Harder answer create a function that does it for you.

BarrMan
02-23-2006, 12:09 PM
there's gotta be a way to handle this kind of search.
i think it even should be simple, i just can't think of something that does what i want.
i thought about an array to put the form elements inside.

Dim Array()
ReDim Array(2) = (request.form("keyword"),request.form("type"),request.form("location"))
For i = 0 to UBount(Array)
If Array(i) = "" Then
ReDim Preserve UBound(Array-1)
End If


I don't know how to continue and i don't know if this code is right.

Archangel
02-23-2006, 01:03 PM
I'm a little confused where you say you want your SQL statement to search for empty fields.

Do you mean that you simply want the SQL statement to be comprised of the filled in fields???

BarrMan
02-23-2006, 01:16 PM
I'm a little confused where you say you want your SQL statement to search for empty fields.

Do you mean that you simply want the SQL statement to be comprised of the filled in fields???
yes. but i need it to check if the fields are null and if not, add them to the statement.

BarrMan
02-23-2006, 05:33 PM
Here it is:

If IsNull(item) Or Realm = "0" Or Core = "0" Then
Dim SQL
SQL = "SELECT * FROM itemlist WHERE 1=1"
If Not IsNull(item) Then
SQL = SQL & " AND item LIKE '%" & item & "%'"
End If
If Not Realm = "0" Then
SQL = SQL & " AND Realm='" & Realm & "'"
End If
If Not Core = "0" Then
SQL = SQL & " AND Core='" & Core & "'"
End If
Else
SQL = "SELECT * FROM ItemList WHERE item LIKE '%" & item & "%' AND Realm='" & Realm & "' AND Core='" & Core & "'"
End If

SpirtOfGrandeur
02-23-2006, 06:02 PM
ASP:

SQL = "SELECT * FROM itemlist WHERE 1=1"
for each q in Request.QueryString
if Not (StrComp(Trim( Request.QueryString(q) ), vbNullString, 1 ) = 0 or StrComp(Trim( Request.QueryString(q) ), "0", 1 ) = 0) then
if InStr( 1, "item;", q & ";", 1 ) > 0 then
SQL = SQL & " AND " & q & " like '%" & Request.QueryString(q) & "%'"
elseif InStr( 1, "Realm;Core;", q & ";", 1 ) > 0
SQL = SQL & " AND " & q & " = '" & Request.QueryString(q) & "'"
end if
end if
next

BarrMan
02-24-2006, 03:12 PM
thx! i prefer it the easier way though :P ty.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum