Bluehost.com Web Hosting $6.95

random question generation

This is a discussion on random question generation within the PHP General forums, part of the PHP Programming Forums category; I am building an application that has course material and one of the requirments is that questions related to course ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-01-2003
Frank Tudor
 
Posts: n/a
Default random question generation

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?

Frank

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
Reply With Quote
  #2 (permalink)  
Old 12-01-2003
Justin French
 
Posts: n/a
Default Re: [PHP] random question generation

On Tuesday, December 2, 2003, at 02:01 AM, Frank Tudor wrote:

> 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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0