|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
||||
|
||||
|
Hey im doing an application in which a person can search by keywords. There is one and only 1 textbox called "keyword" but i want it to search through 3 colums (details1, details2, details3). I can get it to look at and display correctly when i make it search through only 1 of the details columns but not all 3. heres the script ive tried, any ideas?
at top Code:
<CFPARAM NAME="SESSION.alas.keyword" TYPE="string" DEFAULT="">
<CFIF IsDefined("FORM.keyword")>
<CFSET SESSION.alas.keyword= FORM.keyword>
</CFIF>
heres what ive tried 1. Code:
<CFQUERY NAME="search" DATASOURCE="bt">
SELECT * FROM Alas1
WHERE 0=0
<CFIF SESSION.alas.keyword IS NOT "">
AND detail1 LIKE '%#SESSION.alas.keyword #%'
AND detail2 LIKE '%#SESSION.alas.keyword #%'
AND detail3 LIKE '%#SESSION.alas.keyword #%'
</CFIF>
that didnt work so i did... . Code:
<CFQUERY NAME="search" DATASOURCE="bt">
SELECT * FROM Alas1
WHERE 0=0
<CFIF SESSION.alas.keyword IS NOT "">
AND detail1 LIKE '%#SESSION.alas.keyword #%'
</CFIF>
<CFIF SESSION.alas.keyword IS NOT "">
AND detail2 LIKE '%#SESSION.alas.keyword #%'
</CFIF>
<CFIF SESSION.alas.keyword IS NOT "">
AND detail3 LIKE '%#SESSION.alas.keyword #%'
</CFIF>
any help is appreciated |
|
#2
|
||||
|
||||
|
"WHERE 0=0"
What the hell is this? Take that crap out and then see if it works. You probably also want your "AND" s to be "OR" s instead. Also, are you getting an SQL error or a CF error. Make sure you have all of this surrounded by <cfoutput> tags. Hope that helps. |
|
#3
|
||||
|
||||
|
The '0=0' is a little trick to make the dynamic query logic easier to code. It shouldn't adversely affect the outcome of the query.
|
|
#4
|
|||
|
|||
|
Use 'OR' instead of 'AND"
Where you have the multiple WHERE alias(s) try using 'or" instead of 'AND'.
|
|
#5
|
|||
|
|||
|
Yes, you want to use OR, not AND.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#6
|
||||
|
||||
|
thx a lot guys, you got me on the right track...i kept playing with it and even add 3 textboxes so people can insert 3 diferent keywords which will search through 3 different columns to only produce results with all of the keywords written.
It turned out like this... Code:
<CFQUERY NAME="search" DATASOURCE="bt">
SELECT * FROM Alas1
WHERE 0=0
<CFIF SESSION.alas.keyword1 IS NOT "">
AND (detail1 LIKE '%#SESSION.alas.keyword1 #%'
OR detail2 LIKE '%#SESSION.alas.keyword1 #%'
OR detail3 LIKE '%#SESSION.alas.keyword1 #%')
</CFIF>
<CFIF SESSION.alas.keyword2 IS NOT "">
AND (detail1 LIKE '%#SESSION.alas.keyword2 #%'
OR detail2 LIKE '%#SESSION.alas.keyword2 #%'
OR detail3 LIKE '%#SESSION.alas.keyword2 #%')
</CFIF>
<CFIF SESSION.alas.keyword3 IS NOT "">
AND (detail1 LIKE '%#SESSION.alas.keyword3 #%'
OR detail2 LIKE '%#SESSION.alas.keyword3 #%'
OR detail3 LIKE '%#SESSION.alas.keyword3 #%')
</CFIF>
thx again PS anyone know how to export an SQL database to your hosting company's server when they give u a URL and password? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > 1 textbox to check 3 database columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|