Source Code of quizsam.asp
<%
' math01 or thai01 or engl01
qchoose = request.form("subj") + request.querystring("subj")
' show or check
qprocess = request.form("process") + request.querystring("process")
' default ถ้าไม่มีการส่งค่า จะกำหนดเป็น math01 และ show
if len(qchoose) < 2 then qchoose = "math01"
if len(qprocess) < 2 then qprocess = "show"
'
Set objConn = Server.CreateObject("ADODB.Connection")
Set rec = Server.CreateObject("ADODB.Recordset")
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};" & "DBQ=" & Server.Mappath("\thaiall\db\quiz.mdb")
strSQL = "select * from "& qchoose &";"
rec.Open strSQL, objConn , 2, 3
%>
<html><head><title>ศูนย์สอบ online http://www.thaiall.com/quiz </title></head>
<body bgcolor="#ffffdd"><font face="microsoft sans serif">
ตัวอย่างข้อสอบ online ด้วย ASP (<a href=http://www.thaiall.com target=_blank>thaiall.com</a>)
<ul>
<%
if qprocess = "show" then
response.write(request.form("subj"))
response.write("<form method=post action=http://thaiall.thailandhosting.net/asp/quizsam.asp>")
response.write("<input name=subj type=hidden value=" & qchoose &">")
response.write("<input name=process type=hidden value=check>")
i = 1
if Not rec.eof then rec.MoveFirst
do while Not rec.eof and i <= 10
response.write( "<b>"& i & ". " & rec("question") & "</b> - " & rec("qid") &"<br>")
response.write( "<input type=hidden name=gqid" & i & " value=" & rec("qid") &">")
response.write( "<input type=hidden name=gans" & i & " value=" & rec("ans") &">")
response.write( "<input type=radio name=c" & i & " value=1>ก. " & rec("choice1") &"<br>")
response.write( "<input type=radio name=c" & i & " value=2>ข. " & rec("choice2") &"<br>")
response.write( "<input type=radio name=c" & i & " value=3>ค. " & rec("choice3") &"<br>")
response.write( "<input type=radio name=c" & i & " value=4>ง. " & rec("choice4") &"<br>")
response.write( "<hr>")
rec.MoveNext
i = i + 1
loop
response.write( "<input type=submit name=submit value=ตรวจสอบคำตอบ(Submit)>" )
response.write( "<input type=reset name=reset value=ยกเลิก(Reset)>" )
response.write( "</form><hr>" )
else
i = 1
if Not rec.eof then rec.MoveFirst
do while Not rec.eof and i <= 10
g_qid = request.form("gqid" & i)
g_ans = request.form("gans" & i)
g_c = request.form("c" & i)
response.write( "<b>"& i & ". " & rec("question") & "</b> - " & rec("qid") &"<br>")
if g_qid = rec("qid") then
if g_ans = 1 then
response.write( "<font color=#ff0000>ก. "& rec("choice1") &"</font><br>")
else
response.write( "ก. " & rec("choice1") &"<br>")
end if
if g_ans = 2 then
response.write( "<font color=#ff0000>ข. "& rec("choice2") &"</font><br>")
else
response.write( "ข. " & rec("choice2") &"<br>")
end if
if g_ans = 3 then
response.write( "<font color=#ff0000>ค. "& rec("choice3") &"</font><br>")
else
response.write( "ค. " & rec("choice3") &"<br>")
end if
if g_ans = 4 then
response.write( "<font color=#ff0000>ง. "& rec("choice4") &"</font><br>")
else
response.write( "ง. " & rec("choice4") &"<br>")
end if
if g_ans = g_c then
response.write("<font color=#0000ff>Right.</font>")
else
response.write("Wrong. Try again. [" & g_c & "]")
end if
end if
response.write("<hr>")
rec.MoveNext
i = i + 1
loop
end if
rec.close
set rec = nothing
%>
[ <a href=http://thaiall.thailandhosting.net/asp/quizsam.asp?subj=engl01&process=show>ภาษาอังกฤษเบื้องต้น</a> |
<a href=http://thaiall.thailandhosting.net/asp/quizsam.asp?subj=thai01&process=show>ภาษาไทยเบื้องต้น</a> |
<a href=http://thaiall.thailandhosting.net/asp/quizsam.asp?subj=math01&process=show>คณิตศาสตร์เบื้องต้น</a> ]
</ul>
</body></html>
[ ดูเฉพาะ Source code เท่านั้น |
Run โปรแกรมนี้เพื่อดูเป็นตัวอย่าง ]
|