ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 6th, 2004, 05:40 AM
Alas's Avatar
Alas Alas is offline
Wickedwd.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: wickedwd.com
Posts: 183 Alas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 h 46 m 44 sec
Reputation Power: 0
Exclamation 1 textbox to check 3 database columns

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

Reply With Quote
  #2  
Old October 6th, 2004, 10:05 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 22
Send a message via AIM to bocmaxima
"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.

Reply With Quote
  #3  
Old October 6th, 2004, 01:31 PM
wdn2000's Avatar
wdn2000 wdn2000 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Apr 2000
Posts: 1,058 wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 20 h 56 m 43 sec
Reputation Power: 16
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.

Reply With Quote
  #4  
Old October 6th, 2004, 02:47 PM
mikemac mikemac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Greenville NC
Posts: 70 mikemac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 24 sec
Reputation Power: 4
Use 'OR' instead of 'AND"

Where you have the multiple WHERE alias(s) try using 'or" instead of 'AND'.

Reply With Quote
  #5  
Old October 6th, 2004, 06:21 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
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

Reply With Quote
  #6  
Old October 10th, 2004, 03:45 AM
Alas's Avatar
Alas Alas is offline
Wickedwd.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: wickedwd.com
Posts: 183 Alas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 h 46 m 44 sec
Reputation Power: 0
Thumbs up

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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > 1 textbox to check 3 database columns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway