Current location: Hot Scripts Forums » Other Discussions » Database » need help on randomize question


need help on randomize question

Reply
  #1 (permalink)  
Old 06-10-07, 10:23 PM
James87 James87 is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
need help on randomize question

hi guys, i need help on randomize the questions from access database. what can i do to randomize it? i'm new to vb code. Any help will be greatly appreciated! thx in advance.

below are my code

ASP Code:
  1. <%
  2.     dim numOfItemsPerPage, currentPage, numberForPaging
  3.     numOfItemsPerPage = 5
  4.     'start the main loop to find all the questions
  5.     set RS = Server.CreateObject("ADODB.recordset")
  6.     sql="SELECT * FROM QUESTION "
  7.     on error resume next
  8.     RS.Open sql, conn
  9.     response.Write(request.QueryString("errorStr"))
  10. if not RS.EOF then
  11.     RS.movefirst
  12.     do
  13.         response.write "<b>" & rs("No") & ". " & rs("Question") & "</b><p>" & chr(13)
  14.         'display all available options
  15.         set ORS = Conn.Execute("SELECT * FROM [option] WHERE [QuestionID]=" & RS("QuestionID") )
  16.         if not ORS.EOF then
  17.             ORS.movefirst
  18.             do
  19.             response.write "<input type=Radio Name=""Question" & RS("QuestionID") & """ Value=""Answer" & ORS("OptionID") & """>" & ORS("Option") & "<br>" & chr(13)
  20.                 ORS.movenext
  21.             loop until ORS.EOF
  22.         end if
  23.         response.write "<p>"
  24.         RS.movenext
  25.     loop until RS.EOF
  26.     if err<>0 then
  27.     response.Write(sql)
  28.     end if
  29. end if
  30. conn.close
  31. %>

Last edited by UnrealEd; 06-11-07 at 02:31 AM. Reason: please use the [highlight=ASP] wrapper when posting ASP code
Reply With Quote
  #2 (permalink)  
Old 06-11-07, 07:22 AM
koncept
Guest
 
Posts: n/a
moving to databases

add order by newid()

i do not remember if it is mssql only or access too
Reply With Quote
  #3 (permalink)  
Old 06-19-07, 11:18 AM
Sxooter Sxooter is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
This really depends on how many rows are in your database and what your requirements are.

If there are only few hundred or maybe 5,000 rows in the database, then adding

order by rand() limit 1 is ok.

As your dataset grows, order by rand() becomes progressively slower and unusable. At that point you've got to switch to something else. Generally pre-randomizing either the data in the table, or making a join table with randomized numbers to pick your entries from.

but for smaller datasets, just stick to order by rand() limit 1
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about MySQL. drewhiggins Database 2 01-25-07 10:14 PM
Injecting a string into an If Statement ? nova912 PHP 4 07-21-06 02:04 PM
Posting a question / answer on site markcody PHP 2 11-23-04 01:58 PM
[PHP] Array question UmiSal Script Requests 1 04-05-04 01:52 PM
question and answer software jaydifox C/C++ 0 02-21-04 09:26 AM


All times are GMT -5. The time now is 04:58 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.