Solved

Array parse

Posted on 2008-06-09
5
158 Views
Last Modified: 2013-12-24
I have a variables set in a cookie. It can have a max of three variables, e.g. (17000,18234,21345)
I've tried to loop through them with no success. I need to loop through the cookie and pull each value out and assign the cookie name (CFID) and number to it. For example the first value would be CIDS1 and the second, CIDS2, etc.

<cfset arr = ArrayNew(1)>
<cfloop index="i" list="#CIDS#" delimiters=",">
  <cfset ArrayAppend(arr, i)>
</cfloop>
0
Comment
Question by:usky1
  • 3
  • 2
5 Comments
 

Author Comment

by:usky1
ID: 21746545
I forgot to add the rest of the loop,
<cfloop index="j" from="1" to="#ArrayLen(arr)#">
 <cfoutput> #arr[j]# </cfoutput>
</cfloop>
0
 
LVL 24

Accepted Solution

by:
dgrafx earned 500 total points
ID: 21751264
I guess I don't quite get what you are trying to do (not that it's that important that I understand)
1) you have one cookie whose value is a comma delimited list - correct?
2) you want to loop through this value and create new variables for each one - is that correct?

something like this?
<cfset cids="123,456,789">
<cfset counter=0>
<cfloop index="i" list="#CIDS#" delimiters=",">
<cfset counter=counter+1>
      <cfset "CIDS#counter#"=i>
</cfloop>
<cfloop index="j" from="1" to="#counter#">
<cfoutput>#variables["CIDS" & j]#</cfoutput><br>
</cfloop>

if this isn't close please provide info as to what you want to do in the end - i.e. the concept
0
 

Author Comment

by:usky1
ID: 21751704
1) you have one cookie whose value is a comma delimited list - correct? yes
2) you want to loop through this value and create new variables for each one - is that correct? yes
Sorry for the question confusion. I need to loop through each cookie value and create a new one. For example,
If the cookies first value is 123 I need to do a <cfset number1 = 123>
If the second is 456 then <<cfset number2 = 456>
There are not always three values, there might not even be any depending on previous functions.
How can I loop through and add the cfsets, if existing?
0
 
LVL 24

Expert Comment

by:dgrafx
ID: 21751847
see the code i posted above
this will loop and set the number of vars that you have in your list
if you have  a list of 2 then 2 vars will be set
if you have 5 then 5 will be set
try it out ...

note that the last cfloop in my example is not part of the code but just a way for you to see what has been set
0
 

Author Comment

by:usky1
ID: 21752089
Works great. thanks for your help.
0

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.

Join & Write a Comment

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 …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

15 Experts available now in Live!

Get 1:1 Help Now