Professional Web Applications Themes

assign values to lists - Coldfusion - Getting Started

I have a field in a database that contains the values: 1,0,3,1,1,London When the coldfusion page reads the values it should separate each number and assign a value based on that number. For example if the first number is a 1 then it should display the word "Yes" and then move onto the next number which has a different value assigned to it and so on. Does that make sense?...

  1. #1

    Default assign values to lists

    I have a field in a database that contains the values: 1,0,3,1,1,London

    When the coldfusion page reads the values it should separate each number and
    assign a value based on that number. For example if the first number is a 1
    then it should display the word "Yes" and then move onto the next number which
    has a different value assigned to it and so on.

    Does that make sense?

    csber3 Guest

  2. #2

    Default Re: assign values to lists

    <i>Does that make sense?</i>
    Yes. Now, what's the purpose?


    BKBK Guest

  3. #3

    Default Re: assign values to lists

    If you normalize your database you won't have problems like this.
    Dan Guest

  4. #4

    Default Re: assign values to lists

    Let's say the db field's name is theList.

    Loop through the field values, check if the values are numeric and
    assign your responses with cfSwitch / cfCase statements. If not
    numeric, then show the value.

    <cfloop list="#theList#" index="i">

    <cfif isnumeric(i)>
    <cfswitch expression="#Trim(i)#">
    <cfcase value="0">
    Huh?
    </cfcase>
    <cfcase value="1">
    Yes
    </cfcase>
    <cfcase value="2">
    No
    </cfcase>
    <cfcase value="3">
    Maybe
    </cfcase>
    <cfdefaultcase>
    No clue
    </cfdefaultcase>
    </cfswitch>
    <cfelse>
    #i#
    </cfif>

    </cfloop>

    CFer Guest

  5. #5

    Default Re: assign values to lists

    I agree with previous comment, normalize your database. If possible, take the
    data from that field and create separate columns in the current or new table
    for each value. If you cannot modify data, you can loop thru it using the
    following:

    <cfoutput>
    <cfloop index="i" list="#Trim(your_data)#">
    <cfswitch expression="#Trim(i)#">
    <cfcase value="0">
    No
    </cfcase>
    <cfcase value="1">
    Yes
    </cfcase>
    <cfcase value="3">
    Maybe
    </cfcase>
    <cfcase value="London">
    Condescending
    </cfcase>
    <cfdefaultcase>
    No match found
    </cfdefaultcase>
    </cfswitch>
    <br>
    </cfloop>
    </cfoutput>


    drforbin1970 Guest

Similar Threads

  1. lists and sum of values
    By reN! in forum Macromedia ColdFusion
    Replies: 5
    Last Post: May 13th, 07:53 PM
  2. How to do calculation with the values in 2 form lists?
    By hypamw in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 30th, 08:52 AM
  3. composite control: how to assign initial values to child controls?
    By Ralf Müller in forum ASP.NET Building Controls
    Replies: 5
    Last Post: December 15th, 08:20 AM
  4. Using map to assign var values from hash
    By Richard in forum PERL Miscellaneous
    Replies: 9
    Last Post: October 14th, 04:39 AM
  5. global array, can't assign values from variables
    By Chris Edwards in forum PHP Development
    Replies: 3
    Last Post: September 5th, 08:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139