0
New Here
,
/t5/coldfusion-discussions/loop-in-a-cfc/td-p/747809
Dec 27, 2006
Dec 27, 2006
Copy link to clipboard
Copied
Hi,
am trying to write a query in a Function where i need to return results for a search criteria from a form.
search has 3 drop down lists which has 3 text boxes assigned to retrieve results based on the selection and entering text.
let's say first drop down has a list value of "Customer name" and search value is "John" ..
Query has to retrieve. results where " Customer name" is "John"
like wise i've 3 Dropdown boxes .. which has same list values (i.e., customer name, customer city, country etc.,)
and 3 text boxes, and 2 Operator boxes ("and", "Or) .
Pls.see the Screen Shot here
and i want to retrieve results by looping those 3 list boxes in my Query and sametime using the textbox values and operator.
CFFUCNTION doesn't allow type "struct" in arguments if the return type is "query"
here is the code
<cffunction name="getList" output="true" returntype="query" >
<cfargument name="searchstring" type="any" required="no" default="">
<cfargument name="searchvalue" type="any" required="no" default="">
<cfargument name="operator" type="any" required="no" default="">
<cfquery name="get_values" datasource="#application.dsn#">
SELECT * FROM TABLE
WHERE 0=0
AND
<CFLOOP INDEX="i" list="#arguments.searchstring# delimiters=",">
-- here i need to get the corresponding "textbox" and "Operator" values --
for ex: AND (operator) CUSTOMER_NAME LIKE %JOHN% (textbox value)
</cfloop>
</cfquery>
</cffunction>
Thanks in advance
Weblover.
am trying to write a query in a Function where i need to return results for a search criteria from a form.
search has 3 drop down lists which has 3 text boxes assigned to retrieve results based on the selection and entering text.
let's say first drop down has a list value of "Customer name" and search value is "John" ..
Query has to retrieve. results where " Customer name" is "John"
like wise i've 3 Dropdown boxes .. which has same list values (i.e., customer name, customer city, country etc.,)
and 3 text boxes, and 2 Operator boxes ("and", "Or) .
Pls.see the Screen Shot here
and i want to retrieve results by looping those 3 list boxes in my Query and sametime using the textbox values and operator.
CFFUCNTION doesn't allow type "struct" in arguments if the return type is "query"
here is the code
<cffunction name="getList" output="true" returntype="query" >
<cfargument name="searchstring" type="any" required="no" default="">
<cfargument name="searchvalue" type="any" required="no" default="">
<cfargument name="operator" type="any" required="no" default="">
<cfquery name="get_values" datasource="#application.dsn#">
SELECT * FROM TABLE
WHERE 0=0
AND
<CFLOOP INDEX="i" list="#arguments.searchstring# delimiters=",">
-- here i need to get the corresponding "textbox" and "Operator" values --
for ex: AND (operator) CUSTOMER_NAME LIKE %JOHN% (textbox value)
</cfloop>
</cfquery>
</cffunction>
Thanks in advance
Weblover.
TOPICS
Advanced techniques
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
New Here
,
Dec 29, 2006
Dec 29, 2006
Hi BKBK,
thanks a bunch for your help.. it worked.... i just replaced my code with yours with little modifications..and works perfect..
thanks again.
Weblover.
thanks a bunch for your help.. it worked.... i just replaced my code with yours with little modifications..and works perfect..
thanks again.
Weblover.
LEGEND
,
/t5/coldfusion-discussions/loop-in-a-cfc/m-p/747810#M69716
Dec 27, 2006
Dec 27, 2006
Copy link to clipboard
Copied
It might be simpler to get your query working in a normal
template before adding the complication of a cfc. Try to simplify
as much as you can. Your post leads me to believe you are
overthinking your problem.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/coldfusion-discussions/loop-in-a-cfc/m-p/747811#M69717
Dec 27, 2006
Dec 27, 2006
Copy link to clipboard
Copied
Don't know if it means anything, but you forgot to terminate
your list attribute with a quotation mark. Also, is
arguments.searchstring a list, or a struct? If it's a struct then
it belongs in the collection attribute instead of list, and
requires the item attribute instead of index.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/coldfusion-discussions/loop-in-a-cfc/m-p/747812#M69718
Dec 27, 2006
Dec 27, 2006
Copy link to clipboard
Copied
I hope this points you in the right direction
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/coldfusion-discussions/loop-in-a-cfc/m-p/747813#M69719
Dec 29, 2006
Dec 29, 2006
Copy link to clipboard
Copied
Hi BKBK,
thanks a bunch for your help.. it worked.... i just replaced my code with yours with little modifications..and works perfect..
thanks again.
Weblover.
thanks a bunch for your help.. it worked.... i just replaced my code with yours with little modifications..and works perfect..
thanks again.
Weblover.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/coldfusion-discussions/loop-in-a-cfc/m-p/747814#M69720
Dec 29, 2006
Dec 29, 2006
Copy link to clipboard
Copied
!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

