Solved

Coldfusion - query to list question

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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