3 Replies Latest reply on Jun 21, 2007 10:53 PM by Newsgroup_User

    Loop order

    Damian Dadswell
      Not sure if this is possible but this has to be the best place to ask!

      I have 2 datasources 1 is all the members of my department and another is all the publications the department members have written.

      I have a field in the publications datasource which contains all co-authors which are a mix of external people "full names" and internal people "id's" delimited by |

      now, I have been able to loop through and output the co-authors by outputting full names and then if an id is found replacing it and outputting the full name stored in the database.

      the problem I am having is how can I alphabetically order what I output.
        • 1. Re: Loop order
          Level 7
          one could use listtoarray() and arraysort() functions...

          but if you want to sort by both first name and last name, then you are
          better off populating a temporary query with the name and then ordering it


          Azadi Saryev
          • 2. Re: Loop order
            Damian Dadswell Level 1
            Maybe I should ask in a slightly different way

            if I have a string of names:

            Damian Dadswell, Joe Bloggs

            how can I / am I able to order those alphabetically?
            • 3. Re: Loop order
              Level 7
              your "string of names" is a comma-delimited list. use <cfset myarray =
              listtoarray(yourstringofname, ",") to convert it to an array. then you
              can do <cfset myarray = arraysort(myarray)>

              but be aware of any names that contain a ",", like Joe Smith, Jr. - this
              name will be considered to names in a comma-delimited list.

              once again, repeating myself, if you want to be able to sort your names
              by both first name and last name, then you should populate a temp query
              with the names and then order it and cfoutput it:

              define a temp query with 2 columns (firstname, lastname);
              loop through your list of names, adding a new temp query row and
              populating it with first name and last name with each loop;
              after the loop run a QoQ on the temp q to order it by firstname or lastname;
              cfoutput the QoQ


              Azadi Saryev