Solved

Coldfusion - query to list question

Posted on 2016-10-19
3
72 Views
Last Modified: 2016-10-19
Hello experts .
I need help to output two columns in a list.
I have a code that is working and i'm getting the output i need but i was thinking if i can use another function to 'build' the output (f.e. array).
My code  :

<cfoutput query="data" group="#arguments.sorting#">
     <cfset ruleslist = ''/>
      <cfoutput>
       <cfset listitem = 'testname_' & testname_id &  '=' &  testname_value/>
       <cfset ruleslist = listappend(ruleslist,listitem,'&')/>
      </cfoutput>
        #ruleslist#</br>
</cfoutput

Any help?
0
Comment
Question by:Panos
[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
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41850278
AFAIK, there isn't a cleaner method when dealing with grouped query output.  Personally I don't see anything wrong with your current method.  Some db's like MySQL support functions like GROUP_CONCAT which allow you to build the "list" of values within your SQL, ie

          SELECT  ColumnToGroupBy
                         , GROUP_CONCAT(ColumnToBuildIntoList) AS YourList
          FROM    TableName
          GROUP BY ColumnToGroupBy

However, with all the concatenation required that might end up being less readable IMO.
0
 
LVL 2

Author Comment

by:Panos
ID: 41850316
Thank you very much for your help agx.
I'm sometimes wondering if there would be a better way of doing something.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41850358
Yes, it's good to check the options when working on a section of code.  In this case, that code is probably as good as it gets. As using db functions, does not really buy anything.

Glad I could help.
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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