I am brand new to ColdFusion (as of today in fact). I don't know what version the server is using. I have read through some of http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html to try to get up to speed.
My big question at the moment is: what is the ColdFusion equivalent for this bit of PHP?
$numatt = $HTTP_POST_VARS['numatt'];
$att=explode(",",$numatt);
$attcount = count($att);
Here's the entire PHP script for context:
<?php
$nument = $HTTP_POST_VARS['nument']; # this is one number. My debug example is 2.
$numatt = $HTTP_POST_VARS['numatt']; # this is an indefinite number of numbers separated by commas. My debug example is 3,5.
$numval = $HTTP_POST_VARS['numval']; # this is one number. My debug example is 6.
echo 'number of entities is: $nument<br><br>';
$att=explode(",",$numatt);
$attcount = count($att);
echo 'the attributes are $numatt, which can be broken down to $att[1] and $att[2].<br><br>';
echo 'there are $numval values for each attribute.<br><br>';
for ($i = 1; $i = $nument; $i++) {
echo 'this is round $i of the loop. It has $att[$i] attributes.<br><br>';
for ($j = 1; $j = $att[$i]; $j++) {
echo 'this is for attribute $j of entity $i.<br><br>';
for ($k = 1; $k = $numval; $k++) {
echo 'here is loop $k for $numval values.<br>';
} #end $k
} #end $j
} #end $i
?>
Basically I'll need to translate that from PHP into ColdFusion, but think I can figure out how to set up the loops if I spend enough time in the manuals. (Or I'll come back with more questions...) Pointers to better manuals or getting-started references would also be welcomed - I just found the one linked above via Google.
In ColdFusion, you can easily convert a string into an array by using the listToArray()
function. All form variables are bundled up for you in the form
scope. All url variables are bundled up for you in the url
scope.
<cfoutput>
<!--- reference variables submitted through a form --->
<p>name sent through form: #form.firstName#</p>
<!--- reference variable in url --->
<p>name in url: #url.firstName#</p>
<!--- output a list of all fields submitted in a form --->
<p>all form field names: #form.fieldNames#</p>
<!--- quickly dump form and url data (for debugging purposes) --->
<cfdump var="#form#">
<cfdump var="#url#">
<!--- output all form field data --->
<cfloop collection="#form#" item="key">
Form field name: #key#, form field value: #form[key]#
</cfloop>
<!--- converting strings into arrays, default delimiter is comma --->
<cfset arr1 = listToArray("my,list,is,cool", ",")>
<cfset arr2 = listToArray("my other list", " ")>
<cfset arr3 = listToArray("yet:another:list", ":")>
<!--- how many items in arr1? --->
#arrayLen(arr1)#
<!--- loop over arr3 --->
<cfloop from="1" to="#arrayLen(arr3)#" index="i">
#arr3[i]#
</cfloop>
</cfoutput>
CFML makes most everything easy. Bear in mind, CFML also offers a script syntax if you prefer not to use tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With