<%@ Language="VBScript" %> <% Option Explicit Dim startTime startTime = Timer() Dim conn, sqlQuery, rs Set conn = Server.CreateObject("ADODB.Connection") conn.Open Application("connDVD") 'conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.Mappath("../../database/products.mdb") sqlQuery = "SELECT * FROM dvdCollection ORDER BY " 'NOTE: Switch statement would not work. So I changed it to pass in the exact field name if ( Request.QueryString("sort").Count > 0 ) then sqlQuery = sqlQuery & Request.QueryString("sort") else sqlQuery = sqlQuery & "title" end if 'Response.Write(sqlQuery); Set rs = conn.Execute(sqlQuery) %> DVD Library
DVD Library
VHS is evil

<% Dim oddRow oddRow = true Dim sumTotal sumTotal = 0.00 Dim numRows numRows = 0 Dim paidRows paidRows = 0 Dim dvdTitle Dim dvdPrice while (NOT rs.EOF) if (oddRow) then Response.Write("") oddRow = false else Response.Write("") oddRow = true end if dvdTitle = rs.Fields("title") dvdPrice = rs.Fields("totalPrice") %> <% sumTotal = sumTotal + dvdPrice if (dvdPrice > 0.00) then paidRows = paidRows + 1 numRows = numRows + 1 rs.MoveNext() wend %>
Title of DVD Film Info Purchase Date Vendor Price Paid
<% =dvdTitle %> NetFlix, IMDB <% = rs.Fields("purchaseDate") %> <% = rs.Fields("vendor") %> $<% =dvdPrice %>
Total amount paid for <% = numRows %> movies . . . . $<% = sumTotal %>
Average price paid . . . . <% = FormatValue( sumTotal/numRows ) %>
Average price paid (excluding gifts). . . . <% = FormatValue( sumTotal/paidRows ) %>

Notes:
Any disc with a price of $0 means that it was received as a gift.
IMDB links may not always be exact, since they have a huge catalog of TV shows & movies.
<% Set rs = Nothing conn.Close() Set conn = Nothing %>

<% Dim endTime endTime = Timer() Response.Write "Total time: " & (endTime - startTime) & " seconds." %>