|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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# <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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > searching in an Access database with ColdFusion |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|