Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("dindatabas.mdb")
strSQL = "SELECT c.courseName, cb.courseBookTitle FROM tblCourse c, tblCourseBook cb WHERE cb.courseBookRelation = c.courseId ORDER BY 1"
Set objBook = objConn.Execute(strSQL)
strSQL = "SELECT c.courseName, cm.courseMatFile FROM tblCourse c, tblCourseMat cm WHERE cm.courseMatRelation = c.courseId ORDER BY 1"
Set objMat = objConn.Execute(strSQL)
strSQL = "SELECT DISTINCT courseName FROM tblCourse ORDER BY courseName"
Set objRS = objConn.Execute(strSQL)
Dim arrCourses()
Dim arrBooks(0, 1)
Dim arrMat(0, 1)
i = 0
Do Until objRS.EOF
ReDim Preserve arrCourses(i)
arrCourses(i) = objRS("courseName")
objRS.MoveNext
Loop
Set objRS = Nothing : i = 0
Do Until objBook.EOF
ReDim Preserve arrBooks(i, 1)
arrBooks(i, 0) = objBook("courseBookTitle")
arrBooks(i, 1) = objBook("courseName")
i = i + 1
objBook.MoveNext
Loop
Set objBook = Nothing : i = 0
Do Until objMat.EOF
ReDim Preserve arrMat(i, 1)
arrMat(i, 0) = objMat("courseMatFile")
arrMat(i, 1) = objMat("courseName")
i = i + 1
objRS.MoveNext
Loop
Set objMat = Nothing
objConn.Close : Set objConn = Nothing
For j = 0 To UBound(arrCourses)
Response.Write("<b>" & arrCourses(j) & "</b><br>" & vbCrLf)
strInd = "&nbsp;&nbsp;"
Response.Write(strInd & "Böcker:<br>" & vbCrLf)
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;"
For k = 0 To UBound(arrBooks, 1)
If arrBook(k, 1) = arrCourses(j) Then
Response.Write(strInd & "- " & arrBook(k, 0) & "<br>" & vbCrLf)
Else
Exit For
End If
Next
strInd = "&nbsp;&nbsp;"
Response.Write(strInd & "Filer:<br>" & vbCrLf)
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;"
For l = 0 To UBound(arrMat, 1)
If arrMat(l, 1) = arrCourses(j) Then
Response.Write(strInd & "- " & arrMat(l, 0) & "<br>" & vbCrLf)
Else
Exit For
End If
Next
strInd = ""
Next
Fick inte riktigt till det med ett recordset som du ser. Otestad kod, så det kanske inte funkar. ;)
kolla lite med koden, får fel på line 97
Inkompatibla typer: 'arrBook'
det är alltså detta det blir fel på (röda raden)
For k = 0 To UBound(arrBooks, 1)
[red] If arrBook(k, 1) = arrCourses(j) Then[/red]
Response.Write(strInd & "- " & arrBook(k, 0) & "<br>" & vbCrLf)
Else
Exit For
End If
Next
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("dindatabas.mdb")
strSQL = "SELECT c.courseName, cb.courseBookTitle, (SELECT COUNT(*) FROM tblCourseBook) AS antal FROM tblCourse c, tblCourseBook cb WHERE cb.courseBookRelation = c.courseId ORDER BY 1"
Set objBook = objConn.Execute(strSQL)
strSQL = "SELECT c.courseName, cm.courseMatFile, (SELECT COUNT(*) FROM tblCourseMat) AS antal FROM tblCourse c, tblCourseMat cm WHERE cm.courseMatRelation = c.courseId ORDER BY 1"
Set objMat = objConn.Execute(strSQL)
strSQL = "SELECT DISTINCT courseName FROM tblCourse ORDER BY courseName"
Set objRS = objConn.Execute(strSQL)
Dim arrCourses()
Dim arrBooks()
Dim arrMat()
i = 0
ReDim arrBooks(objBook("antal") - 1, 1)
ReDim arrMat(objMat("antal") - 1, 1)
Do Until objRS.EOF
ReDim Preserve arrCourses(i)
arrCourses(i) = objRS("courseName")
objRS.MoveNext
i = i + 1
Loop
Set objRS = Nothing : i = 0
Do Until objBook.EOF
arrBooks(i, 0) = objBook("courseBookTitle")
arrBooks(i, 1) = objBook("courseName")
i = i + 1
objBook.MoveNext
Loop
Set objBook = Nothing : i = 0
Do Until objMat.EOF
arrMat(i, 0) = objMat("courseMatFile")
arrMat(i, 1) = objMat("courseName")
i = i + 1
objMat.MoveNext
Loop
Set objMat = Nothing
objConn.Close : Set objConn = Nothing
For j = 0 To UBound(arrCourses)
Response.Write("<b>" & arrCourses(j) & "</b><br>" & vbCrLf)
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;"
Response.Write(strInd & "Böcker:<br>" & vbCrLf)
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
For k = 0 To UBound(arrBooks, 1)
If arrBooks(k, 1) = arrCourses(j) Then
Response.Write(strInd & "- " & arrBooks(k, 0) & "<br>" & vbCrLf)
End If
Next
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;"
Response.Write(strInd & "Filer:<br>" & vbCrLf)
strInd = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
For l = 0 To UBound(arrMat, 1)
If arrMat(l, 1) = arrCourses(j) Then
Response.Write(strInd & "- " & arrMat(l, 0) & "<br>" & vbCrLf)
End If
Next
strInd = ""
Next
%>
/red Fortfarande flera recordsets, men nu funkar det! :D
mao... missade helt att du posta så jag gjorde det på ett annat sätt :OO
Undrar egentligen vad som är minst krävande =?
<table width="300" border="1">
<%
Dim objConnect, objRS, SQL, objRSbook, objRSfile, SQLbooks, SQLfiles
Set objConnect = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRSbook = Server.CreateObject("ADODB.Recordset")
Set objRSfile = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT courseId, courseName, courseTeacher FROM tblCourse ORDER BY courseName Asc;"
objConnect.Open(ConnString)
objRS.Open(SQL), objConnect
If Not objRS.EOF Then
Do Until objRS.EOF
%>
<tr>
<td colspan="3"><strong><%=objRS("courseName")%></strong> - <em><%=objRS("courseTeacher")%></em> <a href="course_edit.asp">edit</a></td>
</tr>
<%
showBooks(objRS("courseId"))
showFiles(objRS("courseId"))
objRS.MoveNext
Loop
End If
'## Funktion för att skriva ut alla böcker till en specifik kurs
Function showBooks(id)
SQLbooks = "SELECT courseBookId, courseBookTitle, courseBookAuthor, courseBookIsbn FROM tblCourseBook WHERE courseBookRelation = "& id &" ORDER BY courseBookTitle Asc;"
objRSbook.Open(SQLbooks), objConnect
If Not objRSbook.EOF Then %>
<tr>
<td width="20"> </td>
<td colspan="2">Böcker: <a href="#">lägg till</a> </td>
</tr>
<% Do Until objRSbook.EOF %>
<tr>
<td> </td>
<td width="20"> </td>
<td><a title="<%=objRSbook("courseBookIsbn")%>"><%=objRSbook("courseBookTitle")%> <em>- <%=objRSbook("courseBookAuthor")%></em></a></td>
</tr>
<%
objRSbook.MoveNext
Loop
End IF
objRSbook.Close
End Function
'## Funktion för att skriva ut alla filer för en specifik kurs
Function showFiles(id)
SQLfiles = "SELECT courseMatId, courseMatFile, courseMatFileName FROM tblCourseMaterial WHERE courseMatRelation = "& id &" ORDER BY courseMatFile Asc;"
objRSfile.Open(SQLfiles), objConnect
If Not objRSfile.EOF Then %>
<tr>
<td width="20"> </td>
<td colspan="2">Filer: <a href="#">ladda upp</a> </td>
</tr>
<% Do Until objRSfile.EOF %>
<tr>
<td> </td>
<td> </td>
<td><%=objRSfile("courseMatFile")%> - <a href="<%=objRSfile("courseMatFileName")%>">Ladda
ner</a></td>
</tr>
<%
objRSfile.MoveNext
Loop
End IF
objRSfile.Close
End Function
%></table>
264 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e