Ask a Question related to ASP Database, Design and Development.
-
Jamie Sutherland #1
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
-
Repeating Queries
There must be a more efficient way of producing the attached repeating code: Any help would be appreciated -
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... -
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... -
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... -
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,... -
Bob Barrows #2
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
-
Ray at #3
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
-
Matt Smith #4
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:(depending on how many values DS has)>When the code runs it displays the data from the DB multiple times
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
-
Matt Smith #5
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



Reply With Quote

