Skip to main content
Known Participant
June 12, 2006
Answered

Parse form variable to insert in my query

I have a report where I want to group my output. The only problem is the field I want to group by comes in as a comma deliimeter from the form.

If I use the in() function it doesnt group the output correctly.


<cfoutput>#form.id#</cfoutput><br><br>
<cfquery name="que" datasource="mydsn">
SELECT *
FROM myTable
WHERE id in (#form.id#)
</cfquery>

<cfoutput query="que" group="id">
#id#<br>
<cfoutput>#name#<br></cfoutput>
</cfoutput>


Output -
2
Jones

2
Smith


But if I use one form value at a time it correctly groups my output:

<cfquery name="que" datasource="mydsn">
SELECT *
FROM myTable
WHERE id = 6
</cfquery>


Output -
2
Jones
Smith

Please advise how I can take the form values and input them one at a time in my cfquery?
I assume I need to parse the form.id output and then loop through each value to insert into my cfquery but not sure how I can do this?
    This topic is closed to new replies. Start a new post to keep the conversation going.
    drforbin1970Correct answer
    Inspiring
    June 12, 2006
    An ORDER BY clause in your SQL query could help also. But it's not your SQL query that is the problem, it's how you are formatting your output. Also, you don't need nested CFOUTPUTs.

    3 replies

    drforbin1970Correct answer
    Inspiring
    June 12, 2006
    An ORDER BY clause in your SQL query could help also. But it's not your SQL query that is the problem, it's how you are formatting your output. Also, you don't need nested CFOUTPUTs.
    Translate
    FloridaAuthor
    Known Participant
    June 12, 2006
    Thanks!!

    The ORDER BY solved my problem.
    Translate