GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Sep-2003, 20:16
mlt mlt is offline
New Member
 
Join Date: Sep 2003
Location: Pakistan
Posts: 1
mlt is an unknown quantity at this point

Need a script for selecting random tabels and from those tabels selecting random ques


I am trying to build online exam(test) page which has many mcq's in data base. so hare wht i want to do.

i want to impliment a code in a button that " if i press the next button
it should genrate a random number to pick a table and then from that tabel randomly question is selected. when the user press the button again table is selected randomly and then from that table question is selected randomly.
the sequence of picking tabel and numbers are
table from 1 to 4
questions 1.1,1.2,.....
2.1,2.2,......
3.1,3.2,......
4.1,4.2,......
total number of questions in each table will be 50.
  #2  
Old 12-Sep-2003, 03:18
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
Hey, and welcome to the boards!

Do you know any PHP or mySql? While we're always willing to help out, we'd prefer if you attempted it yourself and got back to us if you've a problem.


So you've decided to have seperate tables for each question, fine. But how to layout those tables. I suggest that each question has an id number, which you can select easily. So the table might look like this:

Code:
table1 id | question | answer_id | answer1 | answer2 ... ------------------------------------------------------------------------------------ 0 | Where .... | 2 | wrong | correct .... 1 | What? | 1 | correct | wrong ...

PHP has a function called rand(int min, int max), which accepts a lower & higer value. For you it would be $random = rand(0, 49), then you can execute the following mysql query:

SELECT * FROM table1 WHERE id = $random;

All this make sense?

Garth Farley
  #3  
Old 12-Sep-2003, 09:01
conkermaniac conkermaniac is offline
Member
 
Join Date: Dec 2001
Location: China
Posts: 174
conkermaniac is on a distinguished road
Hi mlt,

Garth seems to have hit the nail on the head here, but I'll go a bit further. Since you have four tables, you'll need to set up four tables in your MySQL database with the same information. Name them table1, table2, table3, and table4. Then, you'll need to have your script generate a random number using the rand function [$random = rand(1,4);] and concatenate the string "table" with the variable $random. This will give you something like table2 or table3. Store this in a separate variable -- $tablenumber, for example. After you've decided on a table, you'll need to generate another random number to determine which question to extract. I think Garth explained this very nicely, so I won't delve into this. Finally, instead of having the query:

"SELECT * FROM table1 WHERE id = $random"

you'll have something like this:

"SELECT * FROM $tablenumber WHERE id = $random"

I hope this makes some sense.

Conker
__________________
You're not supposed to be looking at this.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:52.


vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.