dawilis
11-11-2003, 11:45 PM
I have so much trouble with loops and SQL strings they drive me nuts
I need to loop through my table getting info based upon the users names, so get the first entry count & display how many times they attended and dates then move onto the next user, and do the same, this is what I have so far but its failing and Im unsure why
<%
' Health table for policy id
Set con = Server.CreateObject("ADODB.Connection")
con.open ="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=" & Server.MapPath(level&"../../db/wic.mdb") & ";"
' Open the NMContacts table
set rs = server.createobject("ADODB.Recordset")
'get max records
SQL = "Select count(*) AS ID From NMContact"
rs.open SQL,con
max = rs("ID")
rs.close
' reopen table
SQL = "Select * from NMContact"
rs.open SQL,con
dim Names(1000)
Names(0) = rs("Name")
rs.close
i = 1
x = 0
SQL = "Select * From NMContact WHERE Name ='"&Names(x)&"'"
rs.open SQL,con
Do while Not rs.EOF
Do while i <= max
if rs("attended") = 1 THEN
attended = "Attended"
' total count for attended sessions
acount = acount + 1
ELSE
attended ="Un-attended"
ucount = ucount + 1
END IF
%>
<tr>
<td><div align="center"><%=i%></div></td>
<td><%=rs("Name")%></td>
<td><div align="center"><%=rs("conDate")%></div></td>
<td><div align="center"><%=rs("ADate")%></div></td>
<td><div align="center"><%=attended%></div></td>
<td><div align="center"><%=acount%></div></td>
</tr>
<%
i = i + 1
rs.movenext
loop
SQL = "Select * From NMContact WHERE Name ='"&Names(x)&"'"
rs.open SQL,con
Names(x+1)
Loop
%>
I need to loop through my table getting info based upon the users names, so get the first entry count & display how many times they attended and dates then move onto the next user, and do the same, this is what I have so far but its failing and Im unsure why
<%
' Health table for policy id
Set con = Server.CreateObject("ADODB.Connection")
con.open ="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=" & Server.MapPath(level&"../../db/wic.mdb") & ";"
' Open the NMContacts table
set rs = server.createobject("ADODB.Recordset")
'get max records
SQL = "Select count(*) AS ID From NMContact"
rs.open SQL,con
max = rs("ID")
rs.close
' reopen table
SQL = "Select * from NMContact"
rs.open SQL,con
dim Names(1000)
Names(0) = rs("Name")
rs.close
i = 1
x = 0
SQL = "Select * From NMContact WHERE Name ='"&Names(x)&"'"
rs.open SQL,con
Do while Not rs.EOF
Do while i <= max
if rs("attended") = 1 THEN
attended = "Attended"
' total count for attended sessions
acount = acount + 1
ELSE
attended ="Un-attended"
ucount = ucount + 1
END IF
%>
<tr>
<td><div align="center"><%=i%></div></td>
<td><%=rs("Name")%></td>
<td><div align="center"><%=rs("conDate")%></div></td>
<td><div align="center"><%=rs("ADate")%></div></td>
<td><div align="center"><%=attended%></div></td>
<td><div align="center"><%=acount%></div></td>
</tr>
<%
i = i + 1
rs.movenext
loop
SQL = "Select * From NMContact WHERE Name ='"&Names(x)&"'"
rs.open SQL,con
Names(x+1)
Loop
%>