Help Please - DB Data Repeating

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Help Please - DB Data Repeating

    Hi,
    Below is the offending code.. When the code runs it displays the data from
    the DB multiple times (depending on how many values DS has). How do I stop
    it doing this and only show the data once but have the relevant checkboxes
    checked.

    Thanks
    Jamie

    DS = "1, 3, 4, 5, 10 , 99"
    objRs.Open strSQL, objConn
    %>
    <table border="1">
    <%
    objRs.MoveFirst
    Do While Not objRs.EOF

    arrTmp = Split(DS, ", ")
    For i = 0 to UBOUND(arrTmp)

    Response.Write ("<tr><td>" & objRs(0) &" - "&objRs(1) &"</td>")
    %>
    <td align="center">
    <input <%If (CStr(arrTmp(i)) = CStr(objRs(0))) Then
    Response.Write("checked") : Response.Write("")%> name="Disablility"
    type="checkbox" value="<%= objRs(0)%>">
    </td></tr>
    <%
    Next
    objRs.Movenext
    loop


    Jamie Sutherland Guest

  2. Similar Questions and Discussions

    1. Repeating Queries
      There must be a more efficient way of producing the attached repeating code: Any help would be appreciated
    2. Repeating Links
      Hello, I have created several pages with several links. When I create a new page, I have to go through each page to add the link and link the...
    3. Non-repeating items
      Hi, Lets say I connected to an Access database and created an sql and then created a drop down list. <% strSQL = "SELECT...
    4. Repeating Column Headers In A Data List
      I have a DataList control which I configured to display in multiple bands (column). I am wondering if it is possible to have the column headers...
    5. Repeating Background
      Truly NEW at this. When I open a new file(jpg) it automatically becomes my background. I then create a new layer but when I open a 2nd image to use,...
  3. #2

    Default Re: Help Please - DB Data Repeating

    Well, it certainly seems to be doing what you told it to do.
    The problem is, I don't understand what you want it to do. Cuold you give
    use a couple sample rows that would typically be contained in objRs and then
    show us what the output should be? (I suspect that the "Response.Write
    ("<tr><td>" & objRs(0) &" - "&objRs(1) &"</td>")" line should be outside of
    (before) the For loop)

    Bob Barrows


    Jamie Sutherland wrote:
    > Hi,
    > Below is the offending code.. When the code runs it displays the data
    > from the DB multiple times (depending on how many values DS has). How
    > do I stop it doing this and only show the data once but have the
    > relevant checkboxes checked.
    >
    > Thanks
    > Jamie
    >
    > DS = "1, 3, 4, 5, 10 , 99"
    > objRs.Open strSQL, objConn
    > %>
    > <table border="1">
    > <%
    > objRs.MoveFirst
    > Do While Not objRs.EOF
    >
    > arrTmp = Split(DS, ", ")
    > For i = 0 to UBOUND(arrTmp)
    >
    > Response.Write ("<tr><td>" & objRs(0) &" - "&objRs(1) &"</td>")
    > %>
    > <td align="center">
    > <input <%If (CStr(arrTmp(i)) = CStr(objRs(0))) Then
    > Response.Write("checked") : Response.Write("")%> name="Disablility"
    > type="checkbox" value="<%= objRs(0)%>">
    > </td></tr>
    > <%
    > Next
    > objRs.Movenext
    > loop


    Bob Barrows Guest

  4. #3

    Default Re: Help Please - DB Data Repeating

    I assume that you aren't referring to the value and the text of the checkbox
    being the same (objRs(0)). So, I'd imagine that your recordset is returning
    your data multiple times. See here, [url]http://www.aspfaq.com/5006[/url], and then
    post the contents of the strSQL variable.

    Ray at work

    "Jamie Sutherland" <jamie.sutherland@no.spam.nhcscotland.com> wrote in
    message news:%23bkv94EUDHA.1912@TK2MSFTNGP12.phx.gbl...
    > Hi,
    > Below is the offending code.. When the code runs it displays the data from
    > the DB multiple times (depending on how many values DS has). How do I stop
    > it doing this and only show the data once but have the relevant checkboxes
    > checked.
    >
    > Thanks
    > Jamie
    >
    > DS = "1, 3, 4, 5, 10 , 99"
    > objRs.Open strSQL, objConn
    > %>
    > <table border="1">
    > <%
    > objRs.MoveFirst
    > Do While Not objRs.EOF
    >
    > arrTmp = Split(DS, ", ")
    > For i = 0 to UBOUND(arrTmp)
    >
    > Response.Write ("<tr><td>" & objRs(0) &" - "&objRs(1) &"</td>")
    > %>
    > <td align="center">
    > <input <%If (CStr(arrTmp(i)) = CStr(objRs(0))) Then
    > Response.Write("checked") : Response.Write("")%> name="Disablility"
    > type="checkbox" value="<%= objRs(0)%>">
    > </td></tr>
    > <%
    > Next
    > objRs.Movenext
    > loop
    >
    >

    Ray at Guest

  5. #4

    Default Re: Help Please - DB Data Repeating

    Quick point: You set arrTmp inside a While Loop that doesn't change the
    value of DS. Do this outside the loop.

    Confusion:
    >When the code runs it displays the data from the DB multiple times
    (depending on how many values DS has)

    This doesn't appear to be true. You display data from the db for as many
    records as are returned from strSQL.

    You appear to be asking:
    How do I make one set of check boxes for many records of data. Storing them
    back where they came from would prove difficult to impossible so I'm
    presuming the results of these check boxes are either for storing elsewhere
    or read-only.

    Assuming this is what you want I would do the something like this:
    Create a 2 dimensional array. Dimension 1 is DS value 1. Dimension 2 is a
    boolean representation of whether or not to display checked.
    cycle through the records but don't create a check box.
    Subloop through the 2dim array. check whether arr(i)=CStr(objRs(0))
    If yes then arr(i)(2)=true.
    When these loops are done you can create your check boxes:
    for each arr(i) make check box. if arr(i)(2) = true then check.

    Hope it helps.

    Matt Smith

    "Jamie Sutherland" <jamie.sutherland@no.spam.nhcscotland.com> wrote in
    message news:%23bkv94EUDHA.1912@TK2MSFTNGP12.phx.gbl...
    > Hi,
    > Below is the offending code.. When the code runs it displays the data from
    > the DB multiple times (depending on how many values DS has). How do I stop
    > it doing this and only show the data once but have the relevant checkboxes
    > checked.
    >
    > Thanks
    > Jamie
    >
    > DS = "1, 3, 4, 5, 10 , 99"
    > objRs.Open strSQL, objConn
    > %>
    > <table border="1">
    > <%
    > objRs.MoveFirst
    > Do While Not objRs.EOF
    >
    > arrTmp = Split(DS, ", ")
    > For i = 0 to UBOUND(arrTmp)
    >
    > Response.Write ("<tr><td>" & objRs(0) &" - "&objRs(1) &"</td>")
    > %>
    > <td align="center">
    > <input <%If (CStr(arrTmp(i)) = CStr(objRs(0))) Then
    > Response.Write("checked") : Response.Write("")%> name="Disablility"
    > type="checkbox" value="<%= objRs(0)%>">
    > </td></tr>
    > <%
    > Next
    > objRs.Movenext
    > loop
    >
    >

    Matt Smith Guest

  6. #5

    Default Re: Help Please - DB Data Repeating

    To define a 2d array with 3 items and a depth of 4:
    Dim name(3,4)

    To reference individual elements e.g element 2 depth 1:
    name(2,1) = "value"

    Matt Smith

    "Jamie Sutherland" <jamie.sutherland@no.spam.nhcscotland.com> wrote in
    message news:uIZ$P2RUDHA.2036@TK2MSFTNGP10.phx.gbl...
    > Matt,
    > Thanks For The Info. I think that is what I need but have never used 2d
    > arrays before and don't know how to do this. Could you please help.
    >
    > Thanks

    Matt Smith 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