程式|線上 Result.asp
這一頁的主要目的是顯示結果,同時將這些結果插入資料庫以備將來參考。
for each item in Request.Form
sql_check = "select Count(*) from "&subject&" where answer ='" & Request.Form(item) & "'"
Set RS_check = Application("Conn").Execute(sql_check)
if RS_check(0) > 0 then
result = result + 1
end if
next
變數result中儲存了結果。
百分數是從result中算出來的,如下所示:
percent = round(( 100 * result )/count)
要將這個結果儲存在資料庫中,執行以下查詢:
sql_id = "select id from loginuser where username='" & Session("username") &"'"
Set RS_id = Application("Conn").Execute(sql_id)
id= RS_id(0)
SQL_insert = "insert into details (ref_id,subject,score) values('" & id & "','" _
& subject & "', '" & percent &"') "
Set RS_insert = Application("Conn").Execute(SQL_insert)
View.asp
觀看模組檢查會員是否以前曾經進行過線上考試。如果是的話,將使用者引導到viewrecord.asp。如果沒有的話,顯示相應的資訊。
sql_id= "select id from loginuser where username='" & Session("username") &"'"
Set RS_id = Application("Conn").Execute(sql_id)
id= RS_id(0)
sql_count = "Select count(*) from details where ref_id = '" & id &"'"
Set RS_count = Application("Conn").Execute(sql_count)
If RS_count(0) < > 0 Then
response.redirect "viewrecord.asp"
End If
If RS_count(0) = 0 Then
Session("noview") = "NO ONLINE EXAMINATIONS HAVE BEEN GIVEN"
response.redirect "default.asp"
End If
Viewrecord.asp
Viewrecord.asp頁使會員能夠觀看一些他們的細節資訊。查詢如下:
sql_details = "Select *subject, score from details where ref_id = '" & id &"'"
Set RS_details = Application("Conn").Execute(sql_details)
結果是用一個簡單的表格格式來顯示的。
請注意,我並沒有將會員可以進行一個主題的考試次數限制為一次。同一個主題考試可以進行任意次。