![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Need a script for selecting random tabels and from those tabels selecting random quesI 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
|
|||
|
|||
|
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:
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
|
|||
|
|||
|
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. |
Recent GIDBlog
2nd Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The