Matching array index to values retrieved from database

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Matching array index to values retrieved from database

    Hello friends,

    I have this dynamic array(shown below) that I need to match to values
    (1 - 10) that I am returning from the database via DSN connection
    object. The values I need to match are on the same page (in their own
    table) but I am not sure how to match up the array indexes to these
    values. I want to be able to display the array result as part of or
    nested in another table.

    Thanks in advance,
    John Wilson
    Programmer/Analyst

    <td valign="top">
    <h3>Dynamic Array</h3>
    <%
    ' Now on to our dynamic array. Before I can use a dynamic array
    ' I need to tell it how many elements I want to be able to put
    ' into it. The ReDim command allows us to redimension an array
    ' to whatever size we need. I'm setting it to 2 elements so I
    ' use an upper bound of 1.

    ReDim arrResponses(9)

    arrResponses(0) = "Q1"
    arrResponses(1) = "Q2"
    arrResponses(2) = "Q3"
    arrResponses(3) = "Q4"
    arrResponses(4) = "Q5"
    arrResponses(5) = "Q6"
    arrResponses(6) = "Q7"
    arrResponses(7) = "Q8"
    arrResponses(8) = "Q9"
    arrResponses(9) = "Q10"

    ' Show what our array currently contains:
    ShowArrayInTable(arrResponses)

    ReDim Preserve arrResponses(15)

    ' Adding another value:
    arrResponses(10) = "Q11"
    arrResponses(11) = "Q12"
    arrResponses(12) = "Q13"
    arrResponses(13) = "Q14"
    arrResponses(14) = "Q15"
    arrResponses(15) = "Q16"

    ' Once again show what our array currently contains:
    ShowArrayInTable(arrResponses)
    %>
    </td>
    John Wilson Guest

  2. Similar Questions and Discussions

    1. Detecting the lenght of a MEMO field retrieved from a SQL database
      Hi using VBScript, SQL, ASP I would like to show the contents of a memo field but only if it is not empty. I can do this with regular text...
    2. Matching values of an 2 arrays then move
      i am pulling data via the param tags in to 2 different arrays. Here is what I want to happen: when value1 of the first array matches pullDate of...
    3. Array Sort Using Regex Matching Fails
      Over the years, I have periodically played with this syntax of regex matching within an array sort. I have tried a lot of syntax changes. Never...
    4. PUZZLE Getting DropDownList Index of Matching Value
      I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item...
    5. Finding the non-matching values collection/array
      Hi all, Ok, lets say I have the following, Request.Form collection which produces this (as the element names) a b c d
  3. #2

    Default Re: Matching array index to values retrieved from database

    From you code, I don't fully understand what you're trying to do. I don't
    see any recordsets or anything. But, are you saying you want to be able to
    pull out values from an array on demand by calling them by their ID from a
    recordset? If so, you could use a dictionary object if you don't want to
    keep
    a recordset open throughout your page. You could do:

    Dim objDict
    Set objDict = Server.CreateObject("Scripting.Dictionary")
    Set rs = YourConnection.Execute("select UniqueID, OtherColumn from yourTable
    where Whatever='whatever'")
    Do While Not rs.EOF
    objDict.Add rs.Fields(0).Value, rs.Fields(1).Value
    rs.MoveNext
    Loop
    rs.Close
    Set rs = nothing
    YourConnection.CLose
    Set YourConnection = Nothing


    Then, if you want to go grab item with ID number 5 at any time, you'd do:

    response.write objDict.Item(5)


    - Your key values (the first argument in the .Add method) have to be
    unique, but if you're using your PK, that'll be fine.
    - Don't forget to destroy your dictionary object when you're all finished
    with it.\

    If I didn't understand what you meant and this makes no sense, sorry.

    Ray at home



    "John Wilson" <john_wilson44@hotmail.com> wrote in message
    news:11b26e83.0307151838.11a5a380@posting.google.c om...
    > Hello friends,
    >
    > I have this dynamic array(shown below) that I need to match to values
    > (1 - 10) that I am returning from the database via DSN connection
    > object. The values I need to match are on the same page (in their own
    > table) but I am not sure how to match up the array indexes to these
    > values. I want to be able to display the array result as part of or
    > nested in another table.
    >
    > Thanks in advance,
    > John Wilson
    > Programmer/Analyst
    >
    > <td valign="top">
    > <h3>Dynamic Array</h3>
    > <%
    > ' Now on to our dynamic array. Before I can use a dynamic array
    > ' I need to tell it how many elements I want to be able to put
    > ' into it. The ReDim command allows us to redimension an array
    > ' to whatever size we need. I'm setting it to 2 elements so I
    > ' use an upper bound of 1.
    >
    > ReDim arrResponses(9)
    >
    > arrResponses(0) = "Q1"
    > arrResponses(1) = "Q2"
    > arrResponses(2) = "Q3"
    > arrResponses(3) = "Q4"
    > arrResponses(4) = "Q5"
    > arrResponses(5) = "Q6"
    > arrResponses(6) = "Q7"
    > arrResponses(7) = "Q8"
    > arrResponses(8) = "Q9"
    > arrResponses(9) = "Q10"
    >
    > ' Show what our array currently contains:
    > ShowArrayInTable(arrResponses)
    >
    > ReDim Preserve arrResponses(15)
    >
    > ' Adding another value:
    > arrResponses(10) = "Q11"
    > arrResponses(11) = "Q12"
    > arrResponses(12) = "Q13"
    > arrResponses(13) = "Q14"
    > arrResponses(14) = "Q15"
    > arrResponses(15) = "Q16"
    >
    > ' Once again show what our array currently contains:
    > ShowArrayInTable(arrResponses)
    > %>
    > </td>

    Ray at Guest

  4. #3

    Default Re: Matching array index to values retrieved from database

    Hello Ray,

    Thanks for the quick response. Your example might be exactly what I need
    and I will try it. What I need to do is populate the array from one
    database table, the values of which I alrady have on my asp page in an
    html table, and match the indexes/keys of that array to an id_field
    value in another html table which is being populated from the values of
    another (db)table. In other words, I have two calls/queries(stored
    procs) going to the database, and once I have the data on the page,
    which I do, then I want to use memory objects (arrays) to make up the
    relationship between the array and the other resultset because, I only
    need to perform an insert/update on one of the tables (the one
    populating the array), but the data is in one row (responses 1-10), but
    the other table has rows(questions) that have to be returned for each
    question in that one row. Hope this wasn't too confusing. If you're
    interested I would be happy to send you whatever you need to take a
    better look.

    TIA,
    John Wilson


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    John Wilson Guest

Posting Permissions

  • You may not post new threads
  • You may 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