dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Random records from a database??

  1. #1
    Join Date
    Feb 2003
    Location
    Ireland
    Posts
    17

    Question Random records from a database??

    Hello there,
    I am attempting to design a quiz program that will select one question at random from a database (MS Access) and display it along with its four possible answers in a form. The ‘Quiz’ table within the database contains 40 questions each with a unique number identifier (i.e QuizID field), four question fields (i.e Question1, Question2 etc) and a field containing the correct answer. The VBScript below connects the database to the form, however I do not know how to randomly generate a question and its choice of answers to the form??
    Do I incorporate further SQL into the query in order to achieve this, or can I use VBScript or JavaScript?? If yes to any of these suggestions, how can I implement them??
    Also, is it possible ensure that questions are not repeated with this code?

    P.S Is it possible to use JavaScript in an ASP form and if so how and where is it declared??

    Any help, suggestions, pointers, or advice would be very welcome!!

    Thanks for reading.

    <%
    Dim accessDb, DSN1, dbConnection, dbQuery, recordSet

    accessDb = "aDatabase.mdb"

    DSN1 = "DRIVER={Microsoft Access Driver (*.mdb)};"
    DSN1 = DSN1 & "DBQ=" & Server.MapPath(accessDb)

    Set dbConnection = Server.CreateObject("ADODB.Connection")
    dbConnection.Open DSN1

    dbQuery = "SELECT Question FROM Quiz"
    Set recordSet = dbConnection.Execute(dbQuery)


    If ((RecordSet.EOF) OR (RecordSet.BOF)) Then

    Response.Write("<h1>No database records found</h1>")

    Else
    Response.Write("<h1>Query Results</h1>")
    Do Until recordSet.EOF
    Response.Write(recordSet("Question"))

    recordSet.MoveNext
    Loop
    End if

    recordSet.Close
    dbConnection.Close

    %>

  2. #2
    Join Date
    Feb 2003
    Location
    Ireland
    Posts
    17

    Question

    Thanks Dave for your comments.

    Just to clarify.
    An ASP is a page written in VBScript executed server side??
    Can you 'embed' JavaScript within ASP and/or VBScript??

    The ASP scripting language, 'ASP/JScript' can you reccommend any links to help me learn more??

    I need to use a database for this quiz, what scripting language do you reccommend??

    Thanks again!!

    Portmoon

  3. #3
    Join Date
    Feb 2003
    Location
    Ireland
    Posts
    17

    Question

    Thanks Dave!

    So, is there any way I can connect to a database using client side code? i.e JavaScript

    As the quiz is not inteneded to go online and security is not an issue, I want to avoid having the code executed server side and work form client side only. Is this possible?

    If this is not possible can I connect the database using VBScript and construct the remainder of the quiz in client side code??

    Thanks!

  4. #4
    Join Date
    Feb 2003
    Location
    Ireland
    Posts
    17

    Thumbs up Thanks!!

    Okay Dave,

    I want to thank you for all your comments and suggestions recently they have been very helpful, especially in clearing up a lot of my misconceptions.

    Cheers!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles