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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 6th, 2004, 03:25 PM
myhomie myhomie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 20 myhomie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
searching in an Access database with ColdFusion

I am trying to work through how to use ColdFusion and SQL to perform this function:

On my website, I have a form that contains 6 fields, 5 text, 1 checkmark. They are (with the form name I gave them):
major
host
fname (firstname)
lname (lastname)
Profession
State

I want to do a search on these fields (which are all in the Alumna table in Access), however - I want to make sure that a user can complete the search with only one, two, etc...up to all of the fields filled in. (thinking about doing on a searchvalidate page)
Once I have completed the search, I want to print out the "match or matches" that come closest to the search results on the search page. How do I go about doing this? Thanks!

Reply With Quote
  #2  
Old October 6th, 2004, 03:48 PM
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
Code:
<cfoutput>
<cfquery>
SELECT * FROM yourTable
WHERE 0=0
<cfif Len(Form.major)>OR major='#Form.major#'</cfif>
<cfif Len(Form.host)>OR host='#Form.host#'</cfif>
<cfif Len(Form.fname)>OR fname='#Form.fname#'</cfif>
<cfif Len(Form.lname)>OR lname='#Form.lname#'</cfif>
<cfif Len(Form.Profession)>OR Profession='#Form.Profession#'</cfif>
<cfif Len(Form.State)>OR State='#Form.State#'</cfif>
</cfquery>
</cfoutput>


The only problem you'll run into is with the checkbox. Change the checkbox field from Len(Form.field) to IsDefined("Form.field") and the value attribute on the checkbox will have to be 1.
If you want them to narrow their search with more fields as opposed to searching all of them, change OR to AND for each one.

Hope that helps.

Reply With Quote
  #3  
Old October 7th, 2004, 07:38 AM
myhomie myhomie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 20 myhomie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Checkbox problem

Alright, so this is what I have and it's helped a bunch. It works until I search for an Alumna and fill in the willHost field. I searched for an Alumna using their first name and I checked their willHost (so that means they will host) and the error message said:

ODBC Error Code = 22005 (Error in assignment)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
SQL = "SELECT * FROM ALUMNA WHERE 0=0 AND WILLHOST='on'AND FIRSTNAME='Katie'"



<cfquery name = "SearchAlumna" dataSource ="AlphaChiOmega">
SELECT * FROM ALUMNA
WHERE 0=0
<cfif Len(Form.major)>AND MAJOR='#Form.major#'</cfif>
<cfif IsDefined("Form.host") >AND WILLHOST='#Form.host#'</cfif>
<cfif Len(Form.fname)>AND FIRSTNAME='#Form.fname#'</cfif>
<cfif Len(Form.lname)>AND LASTNAME='#Form.lname#'</cfif>
<cfif Len(Form.profession)>AND PROFESSION='#Form.Profession#'</cfif>
<cfif Len(Form.state)>AND STATE='#Form.State#'</cfif>
</cfquery>


<cfoutput query="SearchAlumna">
<font size="4"><b>Name:</b></font> #firstName# #lastName# &nbsp;<b> <font size="4">Grad Year:</font></b> #gradYear# <br>
</cfoutput>

*************
I think it's almost there...just a little rough around the edges! Thanks so much for your help.
Also- In my form, I want to do a drop down list for the options (instead of text or checkbox)...how do I go about doing that and filling in the fields? Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > searching in an Access database with ColdFusion


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 2 hosted by Hostway