Skip to main content
Participant
June 24, 2008
Question

CF Query problems

  • June 24, 2008
  • 4 replies
  • 613 views
It should be returning results where whatever was entered into the search box can be any part of the title. If they don't enter anything all search results should return everything. Also the hours should return results as well. Various should return all of the different hours and the others are ranges.

Code is attached...
This topic has been closed for replies.

4 replies

AUSwat12Author
Participant
June 25, 2008
I need help fixing this code in the post above
Inspiring
June 24, 2008
AUSwat12 wrote:
> Better yet, where do i need to fix my code?


What code? What is the problem with this code? What have you tried to
fix this code?
AUSwat12Author
Participant
June 24, 2008
The code that I have in my first post. I need to know what needs to be changed in it so that the search results are narrowed. Here is the link. http://dev-my.alfred.edu/index.cfm/fuseaction/workstudy.search and here is the code:

<cfset form.job = Trim( form.job )>

<CFQUERY NAME="GetJobs" DATASOURCE="#request.workstudydatasource#">
SELECT [ID], job, duties, hours, contact, [date] AS dateSubmitted, qual, avail, wrksty
FROM Jobs
WHERE job like '%#form.job#%'
AND hours like '%#form.hours#%'
<cfif Len(trim(form.job))><!--- don't bother doing this if user didn't enter any keywords... --->
AND (job LIKE '%#form.job#%' OR duties LIKE '%#form.job#%')
</cfif>
ORDER BY [ID] DESC
</CFQUERY>





<cfoutput>
<p><strong>Search Results</strong><br />
Searched for <cfif Len(trim(form.job))>keywords &quot;#HTMLEditFormat(form.job)#&quot;</cfif>
and hours &quot;#HTMLEditFormat(form.hours)#&quot;</p>
</cfoutput>

<cfif GetJobs.RecordCount>
<cfinclude template="out_listjobs.cfm"/>
<cfelse>
<hr width="100%" size="1" color="#999933" />
<p>Sorry, your search didn't return any matches</p>
</cfif>
AUSwat12Author
Participant
June 24, 2008
Better yet, where do i need to fix my code?
Inspiring
June 24, 2008
Basic pseudo code example WHERE clause:

WHERE 1 = 1
if searchTerm
AND searchField LIKE '%searchTerm%'
endif

Repeat and combine for each searchable field.

AUSwat12Author
Participant
June 24, 2008
Alright what about a form field that is a drop down with 3 options???