Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
jmercmon #1
looping over a list problem
I am having a problem looping over a list with some elements that are empty.
Here is a sample of the list: address_street=8349+White+Dr custom=
address_state=FL address_city=Burnsville address_id= first_name=Evan
last_name=Whats As you can see some of the items do not = any thing. I have no
control over this, it is what I get. Here is the code I am using. Basicly I
want to end up with a variable = data so I can use them in the page. <cfloop
index='curLine' list='#datalist#' delimiters='#chr(10)#'> <cfset name =
listGetAt(curLine,1,'=')> <cfset '#name#' = listGetAt(curLine,2,'=')> </cfif>
</cfloop> This is the error I get Invalid list index 2. In function
ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as
the first argument (this list has 1 elements). Valid indexes are in the range 1
through the number of elements in the list. The error occurred in line 33
31 : <cfloop index='curLine' list='#datalist#' delimiters='#chr(10)#'> 32 :
<cfset name = listGetAt(curLine,1,'=')> 33 : <cfset '#name#' =
listGetAt(curLine,2,'=')> 34 : </cfloop> 35 : I know it is because some of
the items in the list do not = anything. I would like to just test first to see
if they don't = any thing and skipp them but as of yet everything I try makes
more errors. Any help would be great thanks Jason
jmercmon Guest
-
Looping a list in SQL 2000 SPROC
Hey guys, just trying to learn something new today and wanted to convert one of my cf pages to a sproc. This page just sets up security for the... -
Problem Looping
I am trying to create an array of structures using data collected from a form. The form contains 5 sets of seven fields each set containing... -
parsing and looping over a list
All, I need to parse a list that looks like this: de={ts '2004-08-06 12:14:00'}|s=title header|entID=15,de={ts '2004-08-06 13:05:00'}|s=title... -
[PHP] Looping through a list - Newbie question
There are a lot of methods. The most common is using an array: $_SESSION = Array ("1","2","3","4","5"); foreach($_SESSION as $id) { echo $id; }... -
Looping through a list - Newbie question
explode() and then foreach are your friends :) explode() using the comma as your separator and then traverse the array using foreach. ... -
ultrafresh #2
Re: looping over a list problem
try replacing all =chr(10) with =(space)chr(10) so before anything treat
your list like a simple string... <cfset mylist = replace('='&chr(10),'=
'&chr(10),'ALL')> then deal with the new list... if that doesn't work with
the space replace it with '=@#$%'&chr(10) the likely hood that the string
combo @#$% will occur naturally in your list is slim to none so then on output
you can replace @#$% with a space... it should work with the '= ' however
then you just need to trim() on output... Ultra
ultrafresh Guest
-
ultrafresh #3
Re: looping over a list problem
oh my now thats all messed up i will retype it... try replacing all =chr(10)
with =(space)chr(10) so before anything treat your list like a simple
string... <cfset mylist = replace(mylist,'='&chr(10),'=
'&chr(10),'ALL')> then deal with the new list... if that doesn't work with
the space replace it with '=@#$%'&chr(10) the likely hood that the string
combo @#$% will occur naturally in your list is slim to none so then on output
you can replace @#$% with a space... it should work with the '= ' however
then you just need to trim() on output... Ultra
ultrafresh Guest
-
jmercmon #4
Re: looping over a list problem
Not really having a problem with the = if I do something like this: <cfloop
index='curLine' list='#cfhttp.FileContent#' delimiters='#chr(10)#'> <cfif
listGetAt(curLine,1,'=') is 'first_name'> <cfset
first_name=listGetAt(curLine,2,'=')> </cfif> </cfloop> I can get the info I
want but the lines that jsut say something= and then nothing will
not work with this either. So not matter if I list them all out like above or
in the first post I have to find some way to skip the ones that are 'something=
'. Like this cfloop index='curLine' list='#datalist#'
delimiters='#chr(10)#'> <cfif SOME CODE TO MAKE IT SKIP IF THE SECOND
ELEMENT IS NOT THERE> <cfset name = listGetAt(curLine,1,'=')> <cfset '#name#' =
listGetAt(curLine,2,'=')> </cfif> </cfloop> I have tryed IsDefined and I get a
really wacky error: Parameter 1 of function IsDefined, which is now
'8349+White+Dr', must be a syntactically valid variable name. Just not sure
what little bit of code I need. I have tried many things but nothing works. I
am game to try anything. Jason
jmercmon Guest
-
MikelBGI #5
Re: looping over a list problem
Here's how I handle empty elements in a list: <cfset
Count=#ListLen(ConditionID)#> <cfloop index='LoopIndex' from='1' to=#Count#>
<CFIF #Evaluate('ParameterExists(ConditionExists#LoopInd ex#)')#> <cfset
ConditionExistsElement = listgetat(#ConditionID#,#LoopIndex#)> <cfelse> <CFSET
ConditionExistsElement = ' '> </cfif> So for your code I would use: <cfloop
index='curLine' list='#datalist#' delimiters='#chr(10)#'> <cfset name =
Evaluate('ParameterExists(listGetAt(curLine,1,'=') ))> <cfset '#name#' =
Evaluate('ParameterExists(listGetAt(listGetAt(curL ine,2,'=')))> </cfif>
</cfloop> Hopefully this helps
MikelBGI Guest



Reply With Quote

