#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    4
    Rep Power
    0

    Question cfloop list doesn't return null values


    I have a list like ",89,90,,87". When I use cfloop go to through it, I only get 3 values instead of 5 with 2 nulls. How do I specify the <cfloop> tag to return 5?

    I want to have something like this:
    <tr><td></td><td>89</td><td>90</td><td></td><td>87</td></tr>

    Instead, I get this:
    <tr><td>89</td><td>90</td><td>87</td></tr>

    Thanks in advance for any help!

    Stelly
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    The unfortunate answer is there is no way to get CFLOOP to do this on its own. CF treats multiple null delimiters as one delimiter, which is a benefit in some situations and a pain in the butt in others. You could either send the string in with spaces between the delimiters, or run a replace function that adds a space after each delimiter, but then you must remember to trim() the value when you use it, like this:

    <cfset list = "1,2,3,,5,,,,9,10">
    <cfset counter = 0>

    <cfoutput>
    <cfloop index="thisElement" list="#replace( list, ',', ', ', 'All' )#" delimiters=",">
    <cfset counter = counter + 1>
    Element #counter#: #trim( thisElement )#<br>
    </cfloop>
    </cfoutput>

    A custom tag or function could also handle this pretty easily.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    4
    Rep Power
    0

    Smile


    Thanks for the tip!

    Stelly

IMN logo majestic logo threadwatch logo seochat tools logo