21. januar 2005 - 22:16Der er
20 kommentarer og 1 løsning
Do While - loop problem
hej
jeg har en total liste hvor hver record bliver vist i dtabasen ud fra et request.querystring - dette virker fint. et af mine felter skal hentes fra en tabel og vises i en dropdown der viser tallene fra 1-50. Der er et tilsvarende felt i hoved tabelen ovr det vaglte nr bliver skrevet i, så jeg kan matche de to tal og så er det meningen at dropdownen skal vise det valgte nr.
jeg kan godt få vist dataen men der er problemer emd mine do while loops, jeg har to, ved ikke om man kan det?
håber der er en som kan finde min fejl koden kommer her:
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="760"> <tr> <td bgcolor="#CC0000"><b><font size="1" color="#FFFFFF">ID</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Navn</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Tlf</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Bestillingsdato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Dato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stade Antal</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 1</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 2</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Betalt</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stadenr.</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Actions</font></b></td> </tr> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb") p=0 IF strDato ="" THEN response.write "Du har ikke valgt en dato!!" ELSE SQL = "SELECT * from main Where Dato='"& strdato &"' ORDER BY ToDayDate" set oRS = oDB.Execute(SQL) oRS.Movefirst DO WHILE NOT oRS.EOF '---------------------------------- if oRS("R1") = "" then R1 = "true" else R1 = "false" end if '---------------------------------- if oRS("R2") = "" then R2 = "true" else R2 = "false" end if '---------------------------------- if oRS("Betalt") = "" then Betalt = "true" else Betalt = "false" end if '---------------------------------- if p=0 then bg="bgcolor='#CCCCCC'" else bg="" End if %> <tr> <td <%= bg %>valign="top"><font size="1"><%= oRS("AutoID") %><input type=hidden name="hidSubmitted" value="<%= oRS("AutoID") %>"></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Navn") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Tlf") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("ToDayDate") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Dato") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("StadeAntal") %></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R1" value="<%= oRS("AutoID") %>" <% if oRS("R1")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R2" value="<%= oRS("AutoID") %>" <% if oRS("R2")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="Betalt" value="<%= oRS("AutoID") %>" <% if oRS("Betalt")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><select name="Dropdown"> <% Set oDB2 = Server.CreateObject("ADODB.connection") oDB2.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
strSQL = "SELECT Stadenr_tal FROM stadenr ORDER By Stadenr_tal " Set DORS = oDB2.Execute(strSQL) Do While Not DORS.EOF IF DORS("Stadenr_tal") = "" Then %> <option value=" <%= DORS("Stadenr_tal")%>"><%= DORS("Stadenr_tal")%></option> <% ELSE %> <option value=" <%= DORS("Stadenr_tal")%>" <% If oRS("StadeNr") = DORS("Stadenr_tal") Then response.Write("selected")%>><%= DORS("Stadenr_tal") %></option> <%
DORS.MoveNext loop End If oDB2.Close set DORS = Nothing %> </select></td> <td <%= bg %>valign="top"><font size="2"></font> <input type="submit" value="Send R1" name="submit"> <input type="submit" value="Send R2" name="submit"> <input type="submit" value="Betalt" name="submit"></td> </tr> <% oRS.MoveNext Loop End IF oDB.Close set oRS = Nothing if p=0 then p=1 else p=0 end if %> </table> <font face="Arial" size="2"> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
SQL= "SELECT COUNT(*) AS antal FROM main WHERE Dato ='" & strDato &"'" set oRS = oDB.Execute(SQL) Response.Write "Antal indtastede bestillinger: " & oRS("Antal") %></font>
<% End if oRS.Movenext oDB.Close set oRS = Nothing %> </font> </form> </body> </html>
Do While Not DORS.EOF IF DORS("Stadenr_tal") = "" Then %> <option value=" <%= DORS("Stadenr_tal")%>"><%= DORS("Stadenr_tal")%></option> <% ELSE %> <option value=" <%= DORS("Stadenr_tal")%>" <% If oRS("StadeNr") = DORS("Stadenr_tal") Then response.Write("selected")%>><%= DORS("Stadenr_tal") %></option> <%
DORS.MoveNext loop End If oDB2.Close set DORS = Nothing %> </select></td> <td <%= bg %>valign="top"><font size="2"></font> <input type="submit" value="Send R1" name="submit"> <input type="submit" value="Send R2" name="submit"> <input type="submit" value="Betalt" name="submit"></td> </tr> <% oRS.MoveNext Loop End IF oDB.Close set oRS = Nothing if p=0 then p=1 else p=0 end if %>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="760"> <tr> <td bgcolor="#CC0000"><b><font size="1" color="#FFFFFF">ID</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Navn</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Tlf</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Bestillingsdato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Dato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stade Antal</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 1</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 2</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Betalt</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stadenr.</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Actions</font></b></td> </tr> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb") p=0 IF strDato ="" THEN response.write "Du har ikke valgt en dato!!" ELSE SQL = "SELECT * from main Where Dato='"& strdato &"' ORDER BY ToDayDate" set oRS = oDB.Execute(SQL) oRS.Movefirst DO WHILE NOT oRS.EOF '---------------------------------- if oRS("R1") = "" then R1 = "true" else R1 = "false" end if '---------------------------------- if oRS("R2") = "" then R2 = "true" else R2 = "false" end if '---------------------------------- if oRS("Betalt") = "" then Betalt = "true" else Betalt = "false" end if '---------------------------------- if p=0 then bg="bgcolor='#CCCCCC'" else bg="" End if %> <tr> <td <%= bg %>valign="top"><font size="1"><%= oRS("AutoID") %><input type=hidden name="hidSubmitted" value="<%= oRS("AutoID") %>"></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Navn") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Tlf") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("ToDayDate") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Dato") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("StadeAntal") %></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R1" value="<%= oRS("AutoID") %>" <% if oRS("R1")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R2" value="<%= oRS("AutoID") %>" <% if oRS("R2")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="Betalt" value="<%= oRS("AutoID") %>" <% if oRS("Betalt")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><select name="Dropdown"> <% Set oDB2 = Server.CreateObject("ADODB.connection") oDB2.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
strSQL = "SELECT Stadenr_tal FROM stadenr ORDER By Stadenr_tal " Set DORS = oDB2.Execute(strSQL) Do While Not DORS.EOF IF DORS("Stadenr_tal") = "" Then %> <option value=" <%= DORS("Stadenr_tal")%>"><%= DORS("Stadenr_tal")%></option> <% ELSE %> <option value=" <%= DORS("Stadenr_tal")%>" <% If oRS("StadeNr") = DORS("Stadenr_tal") Then response.Write("selected")%>><%= DORS("Stadenr_tal") %></option> <%
DORS.MoveNext loop End If oDB2.Close set DORS = Nothing %> </select></font></td> <td <%= bg %>valign="top"><font size="2"></font> <input type="submit" value="Send R1" name="submit"> <input type="submit" value="Send R2" name="submit"> <input type="submit" value="Betalt" name="submit"></td> </tr> <% oRS.MoveNext Loop End IF oDB.Close set oRS = Nothing if p=0 then p=1 else p=0 end if %> </table> <font face="Arial" size="2"> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
SQL= "SELECT COUNT(*) AS antal FROM main WHERE Dato ='" & strDato &"'" set oRS = oDB.Execute(SQL) Response.Write "Antal indtastede bestillinger: " & oRS("Antal") %></font>
<% End if oDB.Close set oRS = Nothing %> </font> </form> </body> </html>
Her re koden hvor jeg har nummereret alle IF of END IF samt DO WHILE og LOOP, håber det hjælper lidt, jeg kan ikke se at der mangler nogen eller at der er for mange, kan I det?
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="760"> <tr> <td bgcolor="#CC0000"><b><font size="1" color="#FFFFFF">ID</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Navn</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Tlf</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Bestillingsdato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Dato</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stade Antal</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 1</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Rykker 2</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Betalt</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Stadenr.</font></b></td> <td bgcolor="#CC0000"><b><font size="2" color="#FFFFFF">Actions</font></b></td> </tr> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb") p=0 IF strDato ="" THEN 'nr I1 response.write "Du har ikke valgt en dato!!" ELSE SQL = "SELECT * from main Where Dato='"& strdato &"' ORDER BY ToDayDate" END IF 'nr I1 set oRS = oDB.Execute(SQL) oRS.Movefirst DO WHILE NOT oRS.EOF 'nr D1 '---------------------------------- if oRS("R1") = "" then 'nr I2 R1 = "true" else R1 = "false" end if 'nr I2 '---------------------------------- if oRS("R2") = "" then 'nr I3 R2 = "true" else R2 = "false" end if 'nr I3 '---------------------------------- if oRS("Betalt") = "" then 'nr I4 Betalt = "true" else Betalt = "false" end if 'nr I4 '---------------------------------- if p=0 then 'nr I5 bg="bgcolor='#CCCCCC'" else bg="" End if 'nr I5 %> <tr> <td <%= bg %>valign="top"><font size="1"><%= oRS("AutoID") %><input type=hidden name="hidSubmitted" value="<%= oRS("AutoID") %>"></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Navn") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Tlf") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("ToDayDate") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("Dato") %></font></td> <td <%= bg %>valign="top"><font size="2"><%= oRS("StadeAntal") %></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R1" value="<%= oRS("AutoID") %>" <% if oRS("R1")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="R2" value="<%= oRS("AutoID") %>" <% if oRS("R2")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><input type="checkbox" id="Checks" name="Betalt" value="<%= oRS("AutoID") %>" <% if oRS("Betalt")&"" = "True" then response.write "checked" end if %>></font></td> <td <%= bg %>valign="top"><font size="2"><select name="Dropdown"> <% Set oDB2 = Server.CreateObject("ADODB.connection") oDB2.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
strSQL = "SELECT Stadenr_tal FROM stadenr ORDER By Stadenr_tal " Set DORS = oDB2.Execute(strSQL) Do While Not DORS.EOF 'nr D2 IF DORS("Stadenr_tal") = "" Then 'nr I6 %> <option value=" <%= DORS("Stadenr_tal")%>"><%= DORS("Stadenr_tal")%></option> <% ELSE %> <option value=" <%= DORS("Stadenr_tal")%>" <% If oRS("StadeNr") = DORS("Stadenr_tal") Then response.Write("selected")%>><%= DORS("Stadenr_tal") %></option> <% End If 'nr I6 %> <% DORS.MoveNext loop 'nr D2 oDB2.Close set DORS = Nothing %> </select></font></td> <td <%= bg %>valign="top"><font size="2"></font> <input type="submit" value="Send R1" name="submit"> <input type="submit" value="Send R2" name="submit"> <input type="submit" value="Betalt" name="submit"></td> </tr> <% oRS.MoveNext Loop 'nr D1 oDB.Close set oRS = Nothing
if p=0 then 'nr I7 p=1 else p=0 end if 'nr I7 %> </table> <font face="Arial" size="2"> <% Set oDB = Server.CreateObject("ADODB.connection") oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../db/lop_2005.mdb")
SQL= "SELECT COUNT(*) AS antal FROM main WHERE Dato ='" & strDato &"'" set oRS = oDB.Execute(SQL) Response.Write "Antal indtastede bestillinger: " & oRS("Antal") %></font>
du havde ret med option linien, der manglede en end if så virker min do while også, men dropdown viser dog ikke noget, så jeg skal lige finkæmme koden igen, men tusind tak for hjælpen.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.