Professional Web Applications Themes

Problem converting list elements to variables - Coldfusion - Advanced Techniques

Hello All Scenario I pass toplist via a URL, the next page recieves, URL.toplist toplist is i.e. 'aaa,bbb,ccc,ddd,eee,fff' Then I run a loop through toplist <CFLOOP index="count" list="#URL.toplist#" > Inside the loop I would like to make a list or array (i dont mind) called the element in toplist and get a query where table item = the same element in toplist. example <cfloop index="count" list= "#URL.toplist"> (which is 'aaa,bbb,sss,ddd,eee,fff') In the loop <cfquery name="getparts" > SELECT parts FROM bom WHERE (partparent LIKE ''#count#') (i.e. first element in list 'aaa') </cfquery> Then I want to output the query to a ...

  1. #1

    Default Problem converting list elements to variables

    Hello All

    Scenario

    I pass toplist via a URL, the next page recieves, URL.toplist

    toplist is i.e. 'aaa,bbb,ccc,ddd,eee,fff'

    Then I run a loop through toplist <CFLOOP index="count" list="#URL.toplist#" >

    Inside the loop I would like to make a list or array (i dont mind) called the
    element in toplist and get a query where table item = the same element in
    toplist.

    example

    <cfloop index="count" list= "#URL.toplist"> (which is
    'aaa,bbb,sss,ddd,eee,fff')
    In the loop

    <cfquery name="getparts" >
    SELECT parts
    FROM bom
    WHERE (partparent LIKE ''#count#') (i.e. first element in list 'aaa')
    </cfquery>


    Then I want to output the query to a list which is called the element in the
    loop.

    <cfset #count# = ValueList('getparts')>

    <CFOUTPUT>#aaa#</CFOUTPUT>

    But i get variable 'aaa' not defined ??

    Im sure i have done this before someway to generate a set of lists or arrays
    (dont mind) called the elements in the original list.

    any pointers please im loosing my will to live :)





    Hagster Guest

  2. #2

    Default Re: Problem converting list elements to variables

    1. Are you using the loop/separate queries because you're not sure how to
    retrieve all the items using single a query?

    2. WHERE (partparent LIKE ''#count#') (i.e. first element in list 'aaa')

    If you're not performing a wildcard match, I think you should be using equals

    WHERE partparent= '#count#'

    3.<CFOUTPUT>#aaa#</CFOUTPUT>
    A variable named #aaa# doesn't exist. I think you mean #count#. It contains
    the current list value.

    But i get variable 'aaa' not defined ??

    mxstu Guest

  3. #3

    Default Re: Problem converting list elements to variables

    More hair pulling.

    Ok I have stripped all code etcv and running with test variables in the
    simplest terms this is what i need to do

    <CFSET testlist = 'AAA,BBB,CCC,FFF'>

    <CFLOOP index='listelement' list = '#testlist#> easy peezy so far

    // want to make an array here called the name of the list element //

    <CFSET #count#=ArrayNew(1)> // makes me an array called 'aaa'

    // now im trying to dynamicaly fill it //

    <CFSET #count#[1] = 'test'> <---- this bit is not working how do i
    fill the array, but i need to fill it using the variable cause i want it to do
    the same for as many elements in the list all on differant array named as the
    list elements.

    </CFLOOP>

    // and then dynamicaly output it , but for now on the test im using the array
    name //
    // so i should have the results
    <CFOUTPUT>
    #aaa[1]#
    #bbb[1]#
    #ccc[1]#
    #ddd[1]#
    </cfoutput>

    and these all should be test





    Hagster Guest

  4. #4

    Default Re: Problem converting list elements to variables

    Note - There are a few typos here, so I'm assuming your loop index is actually
    named "count" and not "listelement".

    I think you are misunderstanding what the code is doing. The code below does
    not create an array named aaa. It sets the value of a variable named "count"
    to a new array. Use cfdump to display all the variables to see what I mean.

    Take a few deep breaths ;-) Can you explain in plain english what you're
    trying to do here.

    <CFSET testlist = "AAA,BBB,CCC,FFF">
    <CFLOOP index="count" list = "#testlist#">
    <CFSET count =ArrayNew(1)>
    <cfdump var="#variables#">
    </CFLOOP>


    mxstu Guest

  5. #5

    Default Re: Problem converting list elements to variables

    Thanks mxstu

    Yes there was typos..

    Ok first ill set the scene
    I have top level parts and child level parts in a database, bills of materials.
    i.e
    Top level part AAA could have a111, a222, a333 child parts under it or in
    simple terms you need a111, a222, a333 to make AAA on a manufacturing line.

    Now what im trying to do is:
    Pass a list of toplevel part numbers 'AAA,BBB,CCC'
    Then loop this list.
    On a pass of the list , lets for example say we are on pass one where the list
    variable is 'AAA'

    Make an array to the name of the list variable so it would be the same as
    <CFSET AAA = ArrayNew(1)> but i do not want to have AAA i want it to use the
    list variable so on each pass of the loop i get a new array called the same as
    the list variable.
    If it was simple that as above i would end up with three arrays called AAA
    BBB CCC..

    In the same loop after the array is made i want to populate it again using the
    list variable and not the array name.

    so in Pseudo code i want something like this.

    templist = 'AAA,BBB,CCC'

    Start Loop index 'count' templist

    Make array ----- #count# = ArrayNew(1)
    Fill array ----- #count# [1] = 'sometext'

    End Loop

    The results would be
    List ---- templist = AAA,BBB,CCC
    Array ---- AAA with position 1 set to 'some text'
    Array ---- BBB with position 1 set to 'some text'
    Array ---- BBB with position 1 set to 'some text'

























    Hagster Guest

  6. #6

    Default Re: Problem converting list elements to variables

    One way to create dynamically named variables is using the "variables"
    structure. However, I'm not sure what your ultimate goal is, so creating
    arrays might not be the most efficient method of achieving your goal. What do
    you need to do with the arrays?



    <CFSET testlist = "AAA,BBB,CCC,FFF">
    <CFLOOP list="#testlist#" index="currValue">
    <CFSET variables[currValue] = ArrayNew(1)>
    <CFSET variables[currValue][1] = "some text">
    <CFOUTPUT>#variables[currValue][1]#<br></CFOUTPUT>
    </CFLOOP>
    <CFDUMP var="#variables#">

    mxstu Guest

  7. #7

    Default Re: Problem converting list elements to variables

    Cool that works a treat.
    Ultimately im doing a big matrix lookup, but im trying to populate it on one
    complete loop pass. Bit tricky to explain but ill give it ago.

    Ill start with an end result.

    what i do is pass how ever many Top level parts to a results page.
    The results page takes each top level part and selects all child parts then
    moves on to the next top level part and so on, The child parts are appended to
    a list then using

    <cfscript>
    function distinctList(list)
    { temp = ""; for (idx=1; idx lte ListLen(list); idx=idx+1)
    { item = ListGetAt(list,idx); if (not
    ListFindNoCase(temp,item)) temp = ListAppend(temp,item);
    } return temp;}
    </cfscript>

    the list is sorted and all dupes got rid of.

    so now i have got a toplevel part list and a child parts list that contains a
    distinct list of all child parts that could go into the top lev parts.

    I want to output the Top level parts along the top and the distinct child list
    down the side then populate the matrix with which child parts are in which
    toplevel part.
    Since i loop through the top parts already and gather the child part info if i
    make arrays named the same as the toplevel parts and populate these in the same
    loop system when i come to output it i can simple line up the arrays to get a
    grid like below.
    TopLevel
    Child.......AAA........BBB.......CCC
    a1..............X.............X..................
    a2..............X.............X..............
    a3.............................X ..........X....
    b2 ..............X................................
    b3............................X..................
    b4..............X............X..........X
    c6............................X..................
    c7..............X............X..............

    sorry for the bad diagram :P

    The parts array down the side is distinct parts to fill all top levels
    then I would output each child array AAA BBB CCC inserting blanks where no
    part match to form a matrix grid.

    Having the ability to dynamicaly creat the child arrays while populating the
    distinct parts array just saves more loops..

    By the way the last post answers my question so unless you just want to
    comment on a more effective way to do this im already doing it now thanks to
    mxstu

    Regards Guy.



    Hagster Guest

Similar Threads

  1. how to diplay database elements using form variables
    By jessyarai in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: October 14th, 03:59 PM
  2. passing variables from select elements in form
    By Thunderbirds in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 18th, 03:15 PM
  3. Group list elements
    By GöTz Verdieck in forum PERL Beginners
    Replies: 4
    Last Post: October 5th, 10:05 AM
  4. [newbie] list elements
    By Guest1 in forum PERL Miscellaneous
    Replies: 13
    Last Post: September 5th, 08:19 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