7 Replies Latest reply on May 18, 2006 6:16 AM by drforbin1970

    values from a list

    kabbi~thkek
      Hello,

      I have a Question. I made an LDAP query. Now in this query I have a attribute called "wMUserHistory" The query for this attribute returns a list like this:

      cn=P148348,ou=staff,o=RUG,c=NL, cn=P141922,ou=staff,o=RUG,c=NL, cn=naam,ou=Adm,o=RUG,c=NL, cn=P137308,ou=staff,o=RUG,c=NL, cn=P218384,ou=staff,o=RUG,c=NL

      What I actually want to do is to remove the characters except the "Pxxxxxx", but in one case there is a name called "naam". So I thougt I should get every separate piece of this list: (cn=P148348,ou=staff,o=RUG is one piece) And remove the characters separate per piece and then afterwards make a list of it again so I can use and insert the (correct) data (user history) into a new table.

      I wanted to depend the characters which have to be removed on the total amount of characters (length) per piece (if length is 27 .... if lenght is 28...... etc)

      Is this possible and how do I get the separate pieces from this list. I know how to remove characters, but I have to know how I can do it per piece.

      Is there someone who can help?

      Thank you in advance.

      Regards,

      Kabbi


        • 1. values from a list
          Dan Bracuk Level 5
          It looks like you can treat it as nested lists. Your big list is comma delimted and your little lists are delimited by equal signs. Your logic would be,
          Get the list element of the big list.
          If this element is "ou=staff", go to the previous element of the big list, and do a listlast from the little list.

          • 2. Re: values from a list
            drforbin1970 Level 1
            I've made some assumptions from viewing your data. Looks like cn= value is the key and each row has four columns cn,ou,o,c.

            Try this:

            <!--- *** YOUR DATA --->
            <cfset LDAP_data = "cn=P148348,ou=staff,o=RUG,c=NL, cn=P141922,ou=staff,o=RUG,c=NL, cn=naam,ou=Adm,o=RUG,c=NL, cn=P137308,ou=staff,o=RUG,c=NL, cn=P218384,ou=staff,o=RUG,c=NL">

            <cfset kounter = 0>
            <cfloop index="i" list="#LDAP_data#">
            <cfset kounter = kounter + 1>
            <cfif i CONTAINS "cn=">
            <cfset temp_cn = Replace(i,"cn=","","ALL")>
            </cfif>
            <cfif i CONTAINS "ou=">
            <cfset temp_ou = Replace(i,"ou=","","ALL")>
            </cfif>
            <cfif i CONTAINS "o=">
            <cfset temp_o = Replace(i,"o=","","ALL")>
            </cfif>
            <cfif i CONTAINS "c=">
            <cfset temp_c = Replace(i,"c=","","ALL")>
            </cfif>

            <cfif (kounter MOD 4) EQ 0>
            <!--- *** INSERT RECORDS TO NEW EXISTING TABLE --->
            <cfquery name="insert_new_table" datasource="yourDatasource">
            INSERT your_new_table VALUES ('#Trim(temp_cn)#','#Trim(temp_ou)#','#Trim(temp_o)#','#Trim(temp_c)#')
            </cfquery>
            <!--- *** DISPLAY OUTPUT --->
            <cfoutput>
            cn: #temp_cn# / ou: #temp_ou# / o: #temp_o# / c: #temp_c#<br>
            </cfoutput>
            <!--- reset counters and temp variables --->
            <cfset kounter = 0>
            <cfset temp_cn = "">
            <cfset temp_ou = "">
            <cfset temp_o = "">
            <cfset temp_c = "">
            </cfif>
            </cfloop>

            • 3. Re: values from a list
              kabbi~thkek Level 1
              Thank you very much!!

              I'll try the code immediately!

              Regards,

              Kabbi
              • 4. Re: values from a list
                Level 7
                > cn=P148348,ou=staff,o=RUG,c=NL, cn=P141922,ou=staff,o=RUG,c=NL,
                > cn=naam,ou=Adm,o=RUG,c=NL, cn=P137308,ou=staff,o=RUG,c=NL,
                > cn=P218384,ou=staff,o=RUG,c=NL

                You're making your own life a bit difficult by using the same character
                (comma) for delimiting elements of a given address (between each cn, ou, o,
                c), and between each whole address.

                You should make sure to specify a DIFFERENT character for the separator and
                the delimiter. Here's the docs:

                http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000283.htm

                Having done that, you can simple loop over the list of individual addresses
                (using SEPARATOR as the delimiter), then treat an address as a list
                delimited by DELIMITER (get the CN part by using listFirst()), and the
                actual value of the CN by doing a listLast() using = as the delim.

                --
                Adam
                • 5. Re: values from a list
                  kabbi~thkek Level 1
                  Hi,

                  I know managed (thanks!!) to get all the data displayed like this:

                  P148348
                  P141922
                  Roelans
                  P137308
                  P218384

                  I still have one more question I would like the data being displayed in a different order (the other way around,) so starting with P218384 on top and P148348 at the bottom.

                  I tried to do this like this:

                  <cfset temp_cn = ListSort(temp_cn, "", "ASC")>

                  But this doesn't work...

                  If I do it like this:

                  <cfset LDAP_data = ListSort(LDAP_data, "", "ASC", ",")>

                  I get the data displayed in a wrong way (some missing and whitespaces:

                  Roelans

                  P148348
                  )

                  Do you perhaps also have a solution for this problem?

                  Thank you in advance,

                  Regards,

                  Kabbi
                  • 6. Re: values from a list
                    jdeline Level 1
                    Place your results into an array, 1 to n. Then display the array from n to 1.
                    • 7. Re: values from a list
                      drforbin1970 Level 1
                      If you are putting the data back into a SQL/MySql table, can't you use that to sort the data the way you wish?