An interesting case

Posted on 2003-11-26
Last Modified: 2013-12-24
An interesting case:

I have following array in coldfusion.

QTOT_ARR[1] = 32
QTOT_ARR[2] = 30
QTOT_ARR[3] = 32
QTOT_ARR[4] = 25
QTOT_ARR[5] = 23
QTOT_ARR[6] = 30

The values in this array vary based on the user's input so there are no fixed values. Also, all these six index of array have different names "R I A S E C"  respectively.

I have three text variables. let's say a1, a2, a3.

Now based on the values in the array I want to store the three highest values in a1, a2 and a3 respectively. If there are two highest values (32 in above example) then I want to store both values in the first variable. a1,a2,a3 are text so we can contactenate strings. I want to store the name of the array index, not the value.

To make things easy, the above example will result into the following output.
a1 = RA
a2 = IC
a3 = S

If all the values are same then we will have following:

Note: Please suggest minimum piece of code.

Question by:slatif
  • 5
  • 4
LVL 17

Expert Comment

ID: 9829545
I think converting ur array to a list wld help !

but either ways ... u need to sort [arraysort / listsort] to sort the values & then define how to place their indexes in respective variables [a1,a2,a3]

using list if u r able to get
<Cfset myindex_list = "R,I,A,S,E,C">
<Cfset myvalue_list = "32,30,32,25,23,30">

then by doing a list sort on the myvalue_list & getting corresponding index values from myindex_list wld be easy !
just a thought ... let me know if ur interested !
LVL 12

Expert Comment

ID: 9829553
are you saying that

QTOT_ARR[1] equates to R
QTOT_ARR[2] equates to I
QTOT_ARR[6] equates to C

what are the numeric values for? why not just make a structure that stores R I A S E C?

maybe you could elaborate a little more on what you're doing

Author Comment

ID: 9832221
anandkp: If I sort the myvalue_list then it will rearrange the values. The way it is setup right now, the R stands for first 32(or whatever the first value is), I for 30 and so on. Is there any way I can link these two lists.

jyokum: Yes
QTOT_ARR[1] equates to R
QTOT_ARR[2] equates to I and so on. The numeric values can be any thing for 6 array indexes. In the case above the values are 32 for QTOT_ARR[1], 30 for QTOT_ARR[2]  and so on.
LVL 12

Accepted Solution

jyokum earned 250 total points
ID: 9832760
this works. you'll end up with another array.  I have to ask... what are you doing with this?

<!--- start --->
QTOT_ARR[1] = 32;
QTOT_ARR[2] = 30;
QTOT_ARR[3] = 32;
QTOT_ARR[4] = 25;
QTOT_ARR[5] = 23;
QTOT_ARR[6] = 30;


<cfquery name="qSort" dbtype="query">

<cfset qGroups=ArrayNew(1)>
<cfoutput query="qSort" group="nVal">
      <cfset tempString="">
            <cfset tempString=tempString & qSort.sVal>
      <cfset ret=ArrayAppend(qGroups,tempString)>

<cfdump var="#qGroups#">

Author Comment

ID: 9832981
jyokum: It's asing me for the datasource at <cfquery name="qSort" dbtype="query">.

What should I use here because we are creating the query within the page. So you are using cfquery to sort the query we just made.
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.


Author Comment

ID: 9832996
Is there any way we can sort the query that we make using querynew function?
LVL 12

Expert Comment

ID: 9833395
what version of CF are you using?

> Is there any way we can sort the query that we make using querynew function?
we need to create it the way it is to maintain the original array order. I don't think we could sort it at that point in time even if we wanted to.

Author Comment

ID: 9833405
cold fusion 4.5
LVL 12

Expert Comment

ID: 9833460
I'm pretty sure 4.5 doesn't support   dbtype="query" (a.k.a. query of queries)
too bad, we'll have to come up with something else.

could you please explain what it is you are doing? their may be an easier way to approach this.

Author Comment

ID: 9833567
Thanks jyokum. Your code helped. I already had a query that does what your temp query was doing. I used group option with the query.

<cfoutput query="qSort" group="nVal">
     <cfset tempString="">
--->     <cfoutput>
          <cfset tempString=tempString & qSort.sVal>
     <cfset ret=ArrayAppend(qGroups,tempString)>

How the <cfoutput> (with --->) functions in the above code.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Domino Load Balancer For 2048 Key Requirement 7 35
question about access to website 2 68
Change local server setting in php 6 82
whm high memory usage in processes 7 70
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service ( is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now