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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search a db with multiple form inputs

Status
Not open for further replies.

sanek

Programmer
Jun 9, 2005
6
RU
Could you help me with the following:
I'm making a searh form for a database where the users
can use say 5 different form inputs to search a database.
Now I wonder whow to implement this

Ex. I've got form.Title and form.Author and form.Subject
and I'd like to get the following: if a user only enters one of the fields the rest becomes * so everything is selected. So if he enters nothing the output would ontain the whole db...

Thanks for any suggestions
 
This is how I usually do this type of query.

<cfquery name=&quot;search&quot; .....>
select * from tableName
where 1 = 1
<cfif trim(form.subject) neq &quot;&quot;>
and subject like '%#form.subject#%'
</cfif>
<cfif trim(form.author) neq &quot;&quot;>
and author like '%#form.author#%'
</cfif>
<cfif trim(form.title) neq &quot;&quot;>
and title like '%#form.title#%'
</cfif>
</cfquery>

You can change the comparisons to &quot; title = '#form.title#' &quot; if you want an exact match instead of a partial match.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top