Checkboxes and db

Results 1 to 4 of 4

Thread: Checkboxes and db

  1. #1
    un Guest

    Default Checkboxes and db

    &nbsp;<BR>Hi,<BR>i am trying to write code that displays all the staff names with checkboxes in a list where the staff members belonging to a certain group are checked. But i am not having much success!!<BR>This code results in the list of staff members and checkboxes but none of the check boxes are checked.<BR><BR>RecordSetObjectSta holds all info on staff<BR>RecordSetObjectGM contains all the staff members in the group (ie the records that i want checked)<BR><BR>any help would really be appreciated, thanks<BR>heres my code<BR><BR>&#060;%<BR>While Not RecordSetObjectSta.EOF<BR><BR>dim check<BR>check = ""<BR>%&#062;<BR> &#060;tr&#062;<BR> &#060;%<BR> While Not RecordSetObjectGM.EOF<BR> <BR> If RecordSetObjectSta("StaffID") = RecordSetObjectGM("StaffID") Then<BR> check="YES"<BR> %&#062;<BR> &#060;td&#062;&#060;input type="checkbox" name="staff" value="&#060;%=RecordSetObjectSta("StaffID")%&#062 ;" checked&#062;&#060;%Response.write RecordSetObjectSta("LastName")& " , " &RecordSetObjectSta("FirstName") %&#062;&#060;/td&#062;<BR> <BR> &#060;%<BR> End If<BR> <BR> RecordSetObjectGM.MoveNext<BR><BR> Wend<BR> <BR> If check &#060;&#062; "YES" then<BR> %&#062;<BR> &#060;td&#062;&#060;input type="checkbox" name="staff" value="&#060;%=RecordSetObjectSta("StaffID")%&#062 ;"&#062;&#060;%Response.write RecordSetObjectSta("LastName")& " , " &RecordSetObjectSta("FirstName") %&#062;&#060;/td&#062;<BR> &#060;%<BR> End If<BR> RecordSetObjectSta.MoveNext<BR> <BR><BR><BR><BR>RecordSetObjectSta.MoveNext<BR>Wen d<BR>%&#062;<BR>

  2. #2
    un Guest

    Default Some one help me, please!!!

    Some one help me, please!!!

  3. #3
    Join Date
    Dec 1969

    Default RE: Checkboxes and db

    try moving recorsetobjectgm.movenext<BR>in place of the first recordsetobjectsta.movenext

  4. #4
    Join Date
    Dec 1969

    Default Wow! Is *that* bad code!

    You are doing a loop through one recordset for EVERY record of the other recordset! Horrible! And you continue through the entire inner set even after you get a match! Yuck. But the reason it doesn&#039;t work is because you forgot to go back to the beginning of the inner recordset for each new outer record! That is, you needed *this* sequence of code:<BR><BR>...<BR>check = ""<BR>RecordSetObjectGM.MoveFirst &#039; the line you are missing!<BR>While Not RecordSetObjectGM.EOF<BR> <BR><BR>If you would do an ORDER BY on *both* recordsets, basing the ordering on the same information, then you could move through the sets in parallel and only do one loop through each one.<BR><BR>Of course, the better way would be to reorganize your database in the first place, so that you could do all this with a single query (using a JOIN). But let&#039;s try it as you have it.<BR><BR>I will *assume* that you do *BOTH* SELECTs (from the two tables) using an ORDER BY StaffID. <BR><BR>So now you can do:<BR><BR>&#060;%<BR>Do While Not RS1.EOF<BR>&nbsp; &nbsp; check = ""<BR>&nbsp; &nbsp; If RS1("StaffID") = RS2("StaffID") Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; check = " CHECKED "<BR>&nbsp; &nbsp; &nbsp; &nbsp; RS2.MoveNext &#039; move past the matched one<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; Response.Write "&#060;TD&#062;&#060;INPUT Type=Checkbox ... " & check & "&#062;" & ...<BR>&nbsp; &nbsp; RS1.MoveNext<BR>Loop<BR>%&#062;<BR><BR>Do you see why it works?<BR><BR>Let&#039;s assume that RS1 has records such that the StaffID&#039;s, in order, are:<BR><BR>1 2 3 6 7 8 11 12 15 17<BR><BR>and RS2 has StaffID&#039;s, again in order!, that are:<BR><BR>2 8 11 12<BR><BR>So we start by comparing 1 = 2? Nope, so RS2 stays where it is, no "CHECKED", and RS1 moves forward.<BR><BR>Now we compare 2 = 2? Yep! So RS2 moves forward, yes we are "CHECKED", and RS1 moves forward.<BR><BR>Now we compare 3 = 8? Nope, so RS2 stays where it is, no "CHECKED", and RS1 moves forward.<BR><BR>etc.<BR><BR>Follow the logic? *MUCH* faster code! MUCH!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts