#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    reno
    Posts
    18
    Rep Power
    0

    loading associative arrays


    I am trying to load an associative array from a recordset. Anyone know how to do this?
  2. #2
  3. superficial
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Peterborough, England
    Posts
    188
    Rep Power
    13
    _______________
    Matt
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    NJ
    Posts
    428
    Rep Power
    16
    ASP doesn't have associative arrays like PHP or Perl so it is kind of sucky like that. You'll have to add key/item pairs for each field/value you have in your recordset. you can easily do this with a loop:

    set dict = server.createobject("scripting.dictionary")

    ' assuming you have a recordset already
    for each fld in rs.fields
    dict.add fld, rs(fld)
    next

    think that is right.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    imbrokn wrote
    ASP doesn't have associative arrays like PHP or Perl
    I'm happy to dispute this!

    Come on guys think about what you say before you make broad generalized, wide reaching statements.

    ASP does have associative arrays.

    That is if you use Javascript as the ASP scripting language.

    Code:
    <script language="javascript" runat="server">
    var x = new Array();
    x["dog"] = "black";
    x["cat"] = "ginger";
    </script>
    I think using server side Javascript is not advertised well enough.
    Javascript is a far better language than VBscript in almost all respects.
    --

    ngibsonau
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    reno
    Posts
    18
    Rep Power
    0

    thank you!


    It works now, thanks to all who responded:
    //Model of Associative Array assigned by recordset

    //Creating new Array

    var routeid = 0;
    var routedirection = "";

    var routefinder= new Array()

    <% Do Until rsMisc.EOF %>
    routeid = '<%=rsMisc("FULL_NAME")%>';
    routedirection = '<%=rsMisc("ROUTE_CARDINALITY_ID")%>';
    routefinder[routeid]=[routedirection];
    <% rsMisc.MoveNext
    Loop %>

    //Model of assignment to select

    for(i=0;i<document.ArrayTest.routedir.options.length;i++)
    {
    document.ArrayTest.routedir.options[i] = null;
    }

    //Declare additional counter for boxes
    var nxt = 0;

    //Assigning Select Options from Array
    for(var i in routefinder)
    {
    //Test Code //document.write(i);
    document.ArrayTest.routedir.options[nxt++] = new Option(i, routefinder[i]);
    }

IMN logo majestic logo threadwatch logo seochat tools logo