thaiall logomy background
coding : allthai.quiz. quizran.asp.
my town
Source : Perl | PHP | ASP | JSP | HTML | HTML5 | JavaScript | Java | COBOL | C++ | MS Access | VBNet | VB | Python | โค้ดดี
File : quizran.asp. ID : 4105
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Full
<html><head><title>ข้อสอบสุ่ม จากทั้งหมด: 2549-01-23 (have 20, work 20)</title></head>
<body bgcolor="#ffffdd"><font face="microsoft sans serif" size=0><ul>
<%
dim totscore, totrec, totquiz, programname, connect, rs, sql, scolor, i, qchoose, qprocess, chk, ip, fromquiz, datetimestart, datetimestop, masterpassword, cntsid, itmp, j, found
masterpassword = "thaiall"
programname = "quizran.asp"
totquiz = 20
totscore = 0
redim ran(totquiz)
qchoose = request.form("tbl") + request.querystring("tbl") 
qprocess = request.form("process") + request.querystring("process") 
qip = request.form("ip") + request.querystring("ip") 
qdatetimestart = request.form("datetimestart") + request.querystring("datetimestart")
qdatetimestop = now()
qmasterpassword = request.form("masterpassword") + request.querystring("masterpassword") 
if len(qchoose) < 2 then qchoose = "math101"
if len(qprocess) < 2 then qprocess = "show"
set connect = server.createobject("ADODB.Connection")
' ==========
' It have many method to open file. Some method does not work.
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("quizans.mdb"))
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\yourdir\db\quizans.mdb"))
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\thaiall.com\allthai.quiz\quizans.mdb")
connect.open "provider=microsoft.jet.oledb.4.0; data source="  & Server.MapPath("quizans.mdb")
' ==========
set rs=server.createobject("ADODB.recordset")
sql = "select * from " + qchoose + "ans where sid ='" + request.form("sid") + "'"
rs.open sql,connect,1,3
cntsid = rs.recordcount  
sql = "select * from student where sid='" & request.form("sid") &"'"
sql = sql & " and pass ='" & request.form("pass") &"'"
rs.close
rs.open sql,connect,1,3
totrec = rs.recordcount
if totrec = 0 or masterpassword <> qmasterpassword then
  response.write("Incorrect student id or password")
  response.end
end if
randomize
i = 1
do while i <= totquiz
  itmp = int(rnd * totquiz) 
  found = 0
  for j = 1 to i - 1
    if ran(j) = itmp then found = 1
  next
  if found = 0 then
    ran(i) = itmp
    ' response.write(itmp & " ")
    i = i + 1
  end if
loop
response.write("Student id : " & request.form("sid"))
response.write("<br>Student name : " & rs("sname"))
response.write("<br>Subject : " & request.form("tbl"))
response.write("<br>IP : " & qip)
response.write("<br>Can save this exam : ")
if cntsid > 0 then 
  response.write("No")
else
  response.write("Yes")
end if
response.write("<br>Start : " & qdatetimestart)
sql = "select * from " + qchoose + " order by qid"
rs.close
set rs=server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrec = rs.recordcount
if qprocess = "show" then
  rs.close
  set rs = connect.execute(sql)
  response.write("<form method=post action=" & programname & ">")
  response.write("<input name=masterpassword type=hidden value=" & request.form("masterpassword") &">")
  response.write("<input name=sid type=hidden value=" & request.form("sid") &">")
  response.write("<input name=pass type=hidden value=" & request.form("pass") &">")
  response.write("<input name=ip type=hidden value=" & qip &">")
  response.write("<input name=datetimestart type=hidden value='" & qdatetimestart &"'>")
  response.write("<input name=fromquiz type=hidden value=" & programname &">")
  response.write("<input name=tbl type=hidden value=" & qchoose &">")
  response.write("<input name=process type=hidden value=check>")
  i = 1
  do while i <= totquiz
   rs.movefirst
   rs.move ran(i)
   itmp = ran(i) + 1
'   itmp = i
    response.write("<hr><b>"&i& "." &rs("ques")&"</b> [ "&rs("qid") &_            
    " ]<br><input type=hidden name=gqid" & itmp & " value=" &rs("qid") &">"&_
    "<input type=hidden name=gans" & itmp & " value=" &rs("ans") &">"&_      
    "<input type=radio name=c"&itmp&" value=1 checked>a. "&rs("c1")&"<br>"&_
    "<input type=radio name=c"&itmp&" value=2>b. "&rs("c2")&"<br>"&_      
    "<input type=radio name=c"&itmp&" value=3>c. "&rs("c3")&"<br>"&_   
    "<input type=radio name=c"&itmp&" value=4>d. "&rs("c4")&"<br>"&_   
    "<input type=radio name=c"&itmp&" value=5>e. "&rs("c5")&"<br>")           
    i = i + 1
  loop
  response.write( "<input type=submit name=submit value=SendAns>" )
  response.write( "<input type=reset name=reset value=Reset></form>" ) 
else
  response.write("<br>Stop : " & qdatetimestop)  
  i = 1
'  for i = 1 to totquiz 
  rs.MoveFirst
  do while Not rs.eof and i <= totquiz
'    if  request.form("gqid" & i) = rs("qid") then
    g_qid = request.form("gqid" & i)
    g_ans = request.form("gans" & i)
    g_c = request.form("c" & i)
    response.write( "<hr>"& i & "." & rs("ques") & " [" &  rs("qid") &"]<br>")               
    ' response.write(g_qid & " | " & rs("qid"))
    if g_qid = rs("qid") then     
      if g_ans = 1 then chk="/" else chk="X" end if
      response.write("<font face=fixedsys>" & chk & "</font> a. "& rs("c1") &"<br>") 
      if g_ans = 2 then chk="/" else chk="X" end if
      response.write("<font face=fixedsys>" & chk & "</font> b. "& rs("c2") &"<br>") 
      if g_ans = 3 then chk="/" else chk="X" end if
      response.write("<font face=fixedsys>" & chk & "</font> c. "& rs("c3") &"<br>") 
      if g_ans = 4 then chk="/" else chk="X" end if
      response.write("<font face=fixedsys>" & chk & "</font> d. "& rs("c4") &"<br>")      
      if g_ans = 5 then chk="/" else chk="X" end if
      response.write("<font face=fixedsys>" & chk & "</font> e. "& rs("c5") &"<br>")      
      if g_ans = g_c then 
        response.write("<font color=blue>Right.</font>")
        totscore = totscore + 1
      else
        response.write("<font color=red>Wrong. Try again. [" & g_c & "]</font>")
      end if
    end if
     i = i + 1
'   end if
    rs.MoveNext
  loop
'  next
  response.write("<hr>Total score : " & totscore)
  ' บรรทัดข้างล่างนี้จะทำให้แสดงคะแนน และหยุดให้ดูเพียง 15 วินาที แล้วกลับไปที่หน้า default.asp อีกครั้ง  
  response.write("<meta http-equiv='refresh' content='15;URL=default.asp'> ")    
  if cntsid = 0 then
    sql = "insert into " + qchoose + "ans(sid,score,ip,datetimestart,datetimestop,scriptname,q01,q02,q03,q04,q05,q06,q07,q08,q09,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20)values('"
    sql = sql & request.form("sid") & "'," & totscore & ",'" & qip & "','" & qdatetimestart & "','" & qdatetimestop & "','" & programname & "','"
    for i = 1 to (totquiz - 1) 
      ' sql = sql & request.form("gans" & i)  & "','"
      sql = sql & request.form("c" & i)  & "','"
    next
    ' sql = sql & request.form("gans" & totquiz) & "')"
    sql = sql & request.form("c" & totquiz) & "')"
    connect.execute(sql)
    response.write("<br>Save : ok")
  else
     response.write("<br>Save : error<br>Can not duplicate")
  end if
end if
connect.close
set rs = nothing
set connect = nothing
%>
</ul></body></html>
จำนวน : 156 บรรทัด
าษาเฮชทีเอ็มแอล (HTML = HyperText Markup Language) คือ ภาษาคอมพิวเตอร์ที่ออกแบบมาเพื่อใช้ในการสร้างเว็บเพจที่เรียกดูผ่านทางเว็บเบราว์เซอร์ (Web Browser) เริ่มพัฒนาโดย ทิม เบอร์เนอรส์ ลี (Tim Berners Lee) ในปัจจุบัน HTML ล่าสุดคือ รุ่น 5 เป็นมาตรฐานหนึ่งของ ISO ซึ่งจัดการโดย World Wide Web Consortium (W3C) ในปัจจุบัน ทาง W3C ผลักดัน รูปแบบของ HTML แบบใหม่ ที่เรียกว่า XHTML รุ่นแรกคือ 1.0 (ม.ค.2543) ซึ่งมีโครงสร้างเป็นแบบ XML (eXtensible Markup Language)
าษาพีเอชพี (PHP Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้กับ ตัวแปลภาษา ทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปเอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้
าษาไพทอน (Python Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาแอพพลิเคชั่นโดยไม่ยึดติดกับแพลตฟอร์ม (Platform) และใช้ในงานได้หลายประเภท ทั้งใช้ในการประมวลผลผ่านคอมมานด์ไลน์ หรือเป็นเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้โค้ดให้กับตัวแปลภาษา เพื่อทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปข้อความ เอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้ จุดที่แตกต่างกับภาษาอื่น คือ การรวบรวมจุดเด่นของแต่ละภาษามารวมเข้าด้วยกัน
อสคิวแอล (SQL = Structured Query Language) คือ ภาษาสอบถามข้อมูล หรือภาษาจัดการข้อมูลอย่างมีโครงสร้าง มีการพัฒนาภาษาคอมพิวเตอร์ และโปรแกรมฐานข้อมูลที่รองรับมากมาย เพราะจัดการข้อมูลได้ง่าย เช่น MySQL, MariaDB, MsSQL, PostgreSQL หรือ MS Access เป็นต้น สำหรับโปรแกรมฐานข้อมูลที่ได้รับความนิยมคือ MySQL หรือ MariaDB เป็น Open Source ที่ใช้งานได้ทั้งใน Linux และ Windows
วัสดีชาวโลก (Hello World) คือ ผลลัพธ์ครั้งแรกที่นักพัฒนาโปรแกรมนิยมเลือกใช้แสดงผลในโปรแกรมแรกที่เขียนขึ้นเพื่อทดสอบการทำงาน ข้อความนี้ทำให้นึกถึงมนุษย์ต่างดาวที่มาเยือนโลกและกล่าวกับมนุษย์เมื่อพบกันครั้งแรกในภาพยนตร์
ตัวอย่าง Hello World
ปรับปรุงโปรแกรม source.pl : 2565-07-24
rspsocial
Thaiall.com