Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2004, 11:13 PM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default asp online quiz

Hi

Ths is a detailed explanation of what i really want to do.

When a student logs into my system, they will access the chapter page which has a list of chapters. Each chapter will then be linked to the lesson page where each chapter has more than one lesson stored. So in my database, i have the Chapter Table which stores the ChapterID and ChapterName. While the Lesson Table will store the LessonID, and Lesson Name.

Then the student will click on the lesson wanted and the lesson/quiz will then be displayed in the next page based on the questions in the database. So therefor there will be the Lesson Question Table which stores the QuestionID, Question, Image, and Answer.

So now, i have related these tables and there will be another table which is the Marks Table that stores IDMark,Marks, IDStudent and Date. The problem lies here where im not sure how can i relate the marks table to the lesson questions table. Coz as u can see, i need 3 primary keys for my lesson question table which is the ChapterID,LessonID and QuestionID. The Marks Table has one primary key which is the MarksID. and the StudentID is related to the StudentInfo Table which stores the students infomation.

so, basically the quiz inteface will have the question number, question and the student is required to type in the answer, thus it is a fill-in-the-blank quiz. each question will have one texbox for the answer to be filled in. what i am doing now is that im displaying the textbox together with the question using the For loop and that is another problem that im facing which is how can i code to distinguish the first textbox with the following ones...i know i have to place some sort of an identifier but im not sure how. Then the answer will be validated according to the answers in the database and the next page will display the answers in the database with the answers from the student plus the marks obtained. I am also creating a chart progress report that displays the performance of each student for each set of lessons in each chapter. Ive not started that as i havent finished the quiz module which im explaining to u abt now.

i hope my explanation is good enough for u to figure how my online quiz looks like...its basically database driven and the admin is able to add, delete and edit the question (that part is settled). hope u could reply as soon as possible. thanks a lot Sachin.

PS: Im using ASP VB Script, developing in Macromedia Dreamweaver MX


 
Old February 9th, 2004, 05:50 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default


Here's a suggestion. I would change your db structure slightly to include 5 tables altogether as follows (fields are nested and * is primary key).

Student
* StudentId
    StudentName

Chapter
* ChapterId
    ChapterName

Lesson
* LessonId
    ChapterId
    LessonName

Question
* QuestionId
    LessonId
    Question
    Image

Results
* ResultId
    StudentId
    QuestionId
    Answer

As the student logs in I would set a session variable [ e.g. Session("StudentId") = request("StudentId") ], without the [], as you're going to use that repeatedly in your application. Then, as noted in the structure above, I would keep the questions and answers in two separate tables. There is no point in storing redundant information by having the questions inserted again and again for each student. You also don't need multiple primary keys in your Question table yet either. You would link your Lesson table with the Question table as 'Question.LessonId = Lesson.LessonId'. Which you don't even need yet, unless you're viewing information from both tables. If you needed to see info from all tables, maybe to see a snapshot of the student's results, you select statement would be as follows...

sql = "Select Student.StudentId, Student.StudentName, Chapter.ChapterName, Lesson.LessonName, Question.Question, Results.Answer"
sql = sql & " from Results"
sql = sql & " INNER JOIN Student ON Results.StudentId = Student.StudentId"
sql = sql & " INNER JOIN Question ON Results.QuestionId = Question.QuestionId"
sql = sql & " INNER JOIN Lesson ON Question.LessonId = Lesson.LessonId"
sql = sql & " INNER JOIN Chapter ON Lesson.ChapterId = Chapter.ChapterId"
sql = sql & " where StudentId = " & Session("StudentId")

As far as your text boxes go, I would use a loop to display the textboxes and questions and pass a value within the name of the box as such...


[PAGE1.asp]
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="POST" action="Page2.asp">
<%
    LessonId = request("LessonId")
    set rs = server.createobject("adodb.recordset")
    sql = "select * from Question where LessonId = " & LessonId order by QuestionId"
    rs.open sql, cn
    if not rs.eof then
        do while not rs.eof
        n = n + 1
%>
  <tr>
    <td width="100%">Question <%=n%><br><input type="text" name="Question<%=n%>" size="20"></td>
  </tr>
<%
        rs.movenext
        loop
    end if
    rs.close
    set rs = nothing
%>
  <tr>
    <td width="100%" height="20"></td>
  </tr>
  <tr>
    <td width="100%"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></td>
  </tr>
</form>
</table>



[PAGE2.asp]
To do what you are trying to do, you need to create an array so that you can request the values for each text box from the previous page. You open a recordset similar to that on PAGE1.asp to count the records in your query and then run another recordset to request the values from PAGE1.asp.

<%
    set rsResult = server.createobject("adodb.recordset")

    Dim Question()
    n = 0
    set rs = server.createobject("adodb.recordset")
    sql = "select * from Question where LessonId = " & LessonId order by QuestionId"
    rs.open sql, cn
    if not rs.eof then
        do while not rs.eof
            n = n + 1
        rs.movenext
        loop
    end if
    rs.close
    set rs = nothing


    reDim Question(n)
    n = 0
    set rs = server.createobject("adodb.recordset")
    sql = "select * from Question where LessonId = " & LessonId order by QuestionId"
    rs.open sql, cn
    if not rs.eof then
        do while not rs.eof
        QuestionId = ""
        QuestionId = rs("QuestionId")
            n = n + 1
            Question(n) = request("Question"&n)
            response.write "Question" & n & ": " & Question(n) & "<br>"


            '--write answer to results table--
            sqlResult = "select * from Results"
            sqlResult = sqlResult & " where StudentId = " & Session("StudentId")
            sqlResult = sqlResult & " and QuestionId = " & QuestionId
            rsResult.open sqlResult, cn, 3, 3
            if rsResult.eof then
                rsResult.addnew
                rsResult("StudentId") = Session("StudentId")
                rsResult("QuestionId") = QuestionId
                rsResult("Answer") = Question(n)
                rsResult.update
            end if
            rsResult.close
            '--end writing answer--

        rs.movenext
        loop
    end if
    rs.close
    set rs = nothing
    set rsResult = nothing
%>

This should be pretty close. As you request each value from PAGE1.asp you then write those values to the Results table.

Hope it's not too complicated. Just remember, you pass the ChapterId to the Lesson.asp page, you pass the LessonId to the Question.asp page, and you always have the Session("StudentId") session variable as long as the browser is open. Hope this helps. Let me know how it works or if you have other questions.

Dave






Similar Threads
Thread Thread Starter Forum Replies Last Post
Create an online test using asp.net and C# Alaphat ASP.NET 2.0 Professional 3 April 14th, 2014 06:16 AM
Online quiz/testing application takwirira ASP.NET 1.x and 2.0 Application Design 7 March 5th, 2007 03:17 PM
Online Quiz Application in ASP rathnamv ASP.NET 1.x and 2.0 Application Design 1 February 19th, 2007 11:39 AM
Online editing in asp.net bneeraj General .NET 0 February 3rd, 2005 09:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.