I am building an application that has course material and one of the requirments is that questions related to course material pop up randomly in relation to the question bank and to time.
So if there are 15 pages in a section and four questions need to populate somewhere after page 1 before the end of the section what would you guys use to do this.
The questions and answers will be in a database.
Also a question on page 4 can't be asked on page 1.
The questions will not pop up like a javascript event but lay seeded between the pages it will either happen based on randomization or not.
Anybody been down this road before?
Well, there's many topics here, including page generation, templating, etc etc, but I'll stick to the one in the subject -- random questions.
Store your questions in a database (eg MySQL), and also store the page which they relate to. Your table might look like this:
id,question,answer,page_id
In which case, when it comes time to ask a question after page 3, you can use MySQL's RANDOM() function to retrieve 4 questions:
SELECT * FROM questions WHERE page_id=3 ORDER BY RAND() LIMIT 4
You probably need to take notice of the question id and put it in a hidden form element, so that you know which answer to look for on the next page:
$sql = "SELECT answer FROM questions WHERE id={$_POST['something']}";
Seems easy enough -- what else do you need help with?
Justin French
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php