Solved

Coldfusion - query to list question

Posted on 2016-10-19
3
46 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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