Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts

    Complicated search form

    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.

  • #2
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Easy answer nope. Harder answer create a function that does it for you.
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #3
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    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.
    Code:
    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.

  • #4
    Registered User
    Join Date
    Jan 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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???

  • #5
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Archangel
    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.

  • #6
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Here it is:
    Code:
    		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

  • #7
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ASP:
    Code:
    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
    Last edited by SpirtOfGrandeur; 02-23-2006 at 06:04 PM.
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #8
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    thx! i prefer it the easier way though :P ty.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •