Solved

having a little trouble with a find statement

Posted on 2014-01-16
4
190 Views
Last Modified: 2014-01-17
I'm converting some old code;

<cfif #find("Any US",USREGION)#>
	<cfset querystring = "#querystring#" & "(USREGION IS NOT NULL)" >
	<cfset USREGIONquery = "true">
<cfelse>
	<cfif #find("Carolinas",USREGION)#>
		<cfif USREGIONquery EQ "true">
			<!--- or (USREGION Like '%Carolinas%') --->
			<cfset querystring = "#querystring#" & " or (USREGION Like '%Carolinas%')" > 
		<cfelse>
			<!--- (USREGION Like '%Carolinas%') --->
			<cfset querystring = "#querystring#" & "(USREGION Like '%Carolinas%')" >
			<cfset USREGIONquery = "true">
		</cfif>
	</cfif>
	<cfif #find("Mountain West",USREGION)#>
		<cfif USREGIONquery EQ "true">
			<!--- or (USREGION Like '%Mountain West%') --->
			<cfset querystring = "#querystring#" & " or (USREGION Like '%Mountain West%')" > 
		<cfelse>
			<!--- (USREGION Like '%Mountain West%') --->
			<cfset querystring = "#querystring#" & "(USREGION Like '%Mountain West%')" >
			<cfset USREGIONquery = "true">
		</cfif>
	</cfif>    etc......

Open in new window



To a more dynamic table based code;

<cfinvoke component="services.jobboard" method="getRegions" returnvariable="regions" />
    <cfset USREGIONquery = "false">
    <cfset USREGION = "South">
    <cfset querystring = "(" >

    <cfoutput>
        <cfif #find("Any US",USREGION)#>
            <cfset querystring = "#querystring#" & "(USREGION IS NOT NULL)" >
            <cfset USREGIONquery = "true">
        <cfelse>
            <cfloop query="regions">
                #usregion#-#regions.description#<br>
                #querystring#<br>
                <cfif #find(regions.description,USREGION)#>
                    <cfif USREGIONquery EQ "true">
                        <cfset querystring = "#querystring#" & " or (USREGION Like '%#regions.description#%')" >
                #querystring#<br>
                    <cfelse>
                        <cfset querystring = "#querystring#" & "(USREGION Like '%#regions.description#%')" >
                #querystring#<br>
                        <cfset USREGIONquery = "true">
                    </cfif>
                </cfif>
            </cfloop>
            <cfif USREGIONquery EQ "true">
                <cfset querystring = "#querystring#" & " or (USREGION Like '%All%')" >
                #querystring#<br>
            </cfif>
            <cfif querystring eq "(">
                <cfset querystring = "" >
            <cfelse>
                <cfset querystring = "#querystring#" & ")" >
            </cfif>
            #querystring# 
        </cfif>
    </cfoutput>

Open in new window


The problem is the find function doesn't seem to be working.  I've tried many variations.  The output I get is;

South-New England
(South-Northeast
(South-Mid Atlantic
(South-Southeast
(South-South
(South-Great Lakes
(South-Midwest
(South-South Central
(South-Mountain States
(South-Southern California
(South-Northern California
(South-Southwest
(South-Northwest
(
0
Comment
Question by:lanterv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
mkishline earned 500 total points
ID: 39788863
Couple of thoughts. The first would be to switch your "Find" to "FindNoCase" which will make the search case-insensitive. You may also want to consider doing the same thing for the conditions in your query.

For example:
<cfset querystring = "#querystring# OR (USREGION LIKE '%#regions.description#%') />

Open in new window


Would become:
<cfset querystring = "#querystring# OR (LOWER(USREGION) LIKE '%#LCase(regions.description)#%') />

Open in new window


It may have been lost during your post, but it appears that you're also missing an operator in your <cfelse> block (see below)

<cfinvoke component="services.jobboard" method="getRegions" returnvariable="regions" />
<cfset USREGIONquery = "false">
<cfset USREGION = "South">
<cfset querystring = "" >

<cfoutput>
	<cfif FindNoCase("Any US",USREGION)>
		<cfset querystring = "#querystring# (USREGION IS NOT NULL)" >
		<cfset USREGIONquery = "true">
	<cfelse>
		<cfloop query="regions">
			#usregion#-#regions.description#<br>
			#querystring#<br>
			<cfif FindNoCase(regions.description,USREGION)>
				<cfif USREGIONquery EQ "true">
					<cfset querystring = "#querystring# or (USREGION Like '%#regions.description#%')" >
			#querystring#<br>
				<cfelse>
					<!--- Should have "AND, OR, or some other operator between #querystring# and "(" --->
					<cfset querystring = "#querystring# (USREGION Like '%#regions.description#%')" >
			#querystring#<br>
					<cfset USREGIONquery = "true">
				</cfif>
			</cfif>
		</cfloop>
		<cfif USREGIONquery EQ "true">
			<cfset querystring = "#querystring# or (USREGION Like '%All%')" >
			#querystring#<br>
		</cfif>
		<cfif querystring NEQ "">
			<cfset querystring = "(#querystring#)" />
		</cfif>
		#querystring# 
	</cfif>
</cfoutput>

Open in new window

0
 

Author Comment

by:lanterv
ID: 39788926
<cfif USREGIONquery EQ "true">
means that the query string has already been added to and an and/or is needed.

The findnocase issue is a good one, but the original code didn't use it and worked fine.  I have made the change anyway but it didn't help.
0
 
LVL 12

Expert Comment

by:mkishline
ID: 39788999
In the list of the output that you posted:
South-New England
(South-Northeast
(South-Mid Atlantic
(South-Southeast
(South-South
(South-Great Lakes
(South-Midwest
(South-South Central
(South-Mountain States
(South-Southern California
(South-Northern California
(South-Southwest
(South-Northwest

Is the idea that the desired list should only contain the records whose regions.description contains "South"?
Desired resultset:
South-Southeast, South-South, South-South Central, South-Southern California, South-Southwest

If so, you should switch the arguments you are sending to the find function:
<cfif Find(USREGION, regions.description)>

Open in new window


If I have misidentified what your expected result set should look like, can you provide more detail as to what your desired results would contain?
0
 

Author Comment

by:lanterv
ID: 39789000
I haven't figured out why yet, but the code is working now with the findnocase changes.  Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question