Skip to main content
Participant
April 17, 2008
Question

JAVASCRIPT TO COLDFUSION

  • April 17, 2008
  • 1 reply
  • 240 views
Hello, Im not really familiar with arrays and loops and Im getting stuck.

I pass some javascript vars to a CFM page via URL.
Example Link.


http://localhost/drag/page2.cfm?Groups=group_1,16,20,group_2,2,13,17,group_3,3,11,group_4,9,12,group_5,14,4,group_6,5,10,group_7,6,15,group_8,1,7,group_9,8,19,18,

I managed to put it into an array and here are my results.

array
1 group_1
2 16
3 20
4 group_2
5 2
6 13
7 17
8 group_3
9 3
10 11
11 group_4
12 9
13 12
14 group_5
15 14
16 4
17 group_6
18 5
19 10
20 group_7
21 6
22 15
23 group_8
24 1
25 7
26 group_9
27 8
28 19
29 18

------------------------------------------------------------------------------------
I was wanting to have the array show the data in this fasion so i can insert into db


group_1,16
group_1, 20
group_2, 2
group_2, 13
group_2,17


Here is my code... I would really appreciate any help.

<cfset MyArray = ArrayNew(1)>
<cfset mylist="#URL.Groups#">
<cfloop from="1" to=#ListLen(mylist)# index="i">
<cfset MyArray = ListGetAt(mylist, i)>


<cfoutput>#MyArray
#<br></cfoutput>
</cfloop>


This topic has been closed for replies.

1 reply

Inspiring
April 18, 2008
If the intent is to insert data from your url variable, I don't think an array is necessary. I would loop through the list with some if/else logic. something like

ThisGroup = "nothing";

cfloop list="#url.groups#" index="ThisItem"
if left(ThisItem, 5) is "group"
ThisGroup = ThisItem
else
insert ThisGroup and ThisItem into your db