• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JAVASCRIPT TO COLDFUSION

New Here ,
Apr 17, 2008 Apr 17, 2008

Copy link to clipboard

Copied

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...

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>


TOPICS
Advanced techniques

Views

209

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2008 Apr 18, 2008

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation