Skip to main content
Inspiring
August 17, 2009
Question

Help with Arrays/Structs

  • August 17, 2009
  • 3 replies
  • 772 views

Hello,

I am working on a page where one can browse our users. Each of our users has pieces of information associated with them like "User Type", "Active", "Permissions", etc... I would like each of these pieces of information to act as a filter for the main users query. For instance, if I filter by the Administrator User Type, then the query should pull only those records who are Administrators. (similar to how http://www.newegg.com filters their products)

I am trying to figure out what the best way is to deal with all this data. Right now I am putting each user type into a structure that is nested into an array (see code below). I can't seem to figure out how to access and change the values that are in the nested Structures.

Help!!!

<cfset myArray2 = ArrayNew(1)>
<cfscript>
    filters = ArrayNew(1);
        for(i=1; i lte qSelectAllUserTypes.recordCount; i++){
        "#qSelectAllUserTypes.user_type_description#" = StructNew();
        "#qSelectAllUserTypes.user_type_description#.displayName" = qSelectAllUserTypes["user_type_description"];
        "#qSelectAllUserTypes.user_type_description#.id" = qSelectAllUserTypes["user_type_id"];
        "#qSelectAllUserTypes.user_type_description#.on" = 0;
   
        AddIt = ArrayAppend(filters, "#evaluate(qSelectAllUserTypes.user_type_description)#");
       
       
    }
</cfscript>

array
1
struct
displayNameAdministrator
id6001
on0
2
struct
displayNameBasic Neurology
id1206
on0
3
struct
displayNameBioengineering
id1203
on0
4
struct
displayNameBioinformatics
id1214
on0
    This topic has been closed for replies.

    3 replies

    Inspiring
    August 18, 2009

    When you get down into the messy details of how CF is actually implemented (it's Java, of course...), you do in fact have the same capabilities that you find, for example, in Perl.  (Or insert_your_favorite_language_here.)  An array is a vector.  A structure is an associative hash.  When you do "assignments" to things, you usually wind up with a "reference to" that thing, which means that you can modify the underlying thing.

    The trick...  is to do what you need to do, but to do it in a sane manner.  To make your code be robust and maintainable.  What I do is to define the underlying logic in CFCs ... basically creating an 'object-like' perspective on the whole thing, in which I "call routines in a well-known library" to do this-or-that against what I otherwise regard as "an opaque thing."  All of the manipulations that I need to do, anywhere in the application, are located only here in this CFC, thereby giving me a strong degree of isolation and encapsulation without straying too far from CF's modus operandi.

    jbreslowAuthor
    Inspiring
    August 17, 2009

    Thanks, got it figured out.

    Inspiring
    August 17, 2009

    Looks like it's a lot more complicated than necessary.  If you already have query results, why do you need an array of structures?  Also, what is the overall objective anyway, to update user data?

    jbreslowAuthor
    Inspiring
    August 17, 2009

    That sounds about right, me making it more complicated than it needs to be.

    What I am trying to accomplish is a Browse feature like that on www.newegg.com. When browsing a product category there are sub-categories on the left side of the screen to use as a filter. Clicking on one of these sub-categories will filter the products result display.

    I am trying to figure out what is the best way to keep track of all of the sub-category filters and if they are on or off. Thus the Structure/Array with a flag that tells me if that filter is on or off.