Here's a problem that I run into a lot and have never come up with a
good answer for...
When building a search form that allows to search multiple criteria in a
table(s) - lets say "lname", "category", and "color" for this example -
the user can fill in any one of these, or all of them. So, when building
the query, I always have trouble figuring out what the first item in the
WHERE statement is, because you don't know which field above might or
might not be filled in.
So, if they fill in just "category" and "color" - see the problem?
What's "best practice" for this?
<cfquery name="myQuery">
Select * From Table
Where ???
<cfif IsDefined("form.lname")>
and lname like '%#form.lname#%'
</cfif>
<cfif IsDefined("form.category")>
and lname like '%#form.category#%'
</cfif>
<cfif IsDefined("form.color")>
and lname like '%#form.color#%'
</cfif>
</cfquery>
The form I'm working on have close to 30 possible fields, and spans
several tables...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:219624
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54