欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用ASP开发一个在线考试程序(七)

程序员文章站 2022-05-17 15:42:23
result.  这一页的主要目的是显示结果,同时将这些结果插入以备将来参考。for each item in request.formsql_check = "select co...
result.
  这一页的主要目的是显示结果,同时将这些结果插入以备将来参考。
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)
结果是用一个简单的表格格式来显示的。

  请注意,我并没有将会员可以进行一个主题的考试次数限制为一次。同一个主题考试可以进行任意次。