slatif
asked on
An interesting case
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:
a1 = RIASEC
Note: Please suggest minimum piece of code.
slatif
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:
a1 = RIASEC
Note: Please suggest minimum piece of code.
slatif
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
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
Is there any way we can sort the query that we make using querynew function?
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.
> 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.
ASKER
cold fusion 4.5
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.
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.
ASKER
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>
</cfoutput>
<cfset ret=ArrayAppend(qGroups,te mpString)>
</cfoutput>
How the <cfoutput> (with --->) functions in the above code.
<cfoutput query="qSort" group="nVal">
<cfset tempString="">
---> <cfoutput>
<cfset tempString=tempString & qSort.sVal>
</cfoutput>
<cfset ret=ArrayAppend(qGroups,te
</cfoutput>
How the <cfoutput> (with --->) functions in the above code.
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 !