FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Most efficient way to randomize a quiz from a database
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Most efficient way to randomize a quiz from a database [message #170565 is a reply to message #170563] Mon, 08 November 2010 16:26 Go to previous messageGo to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma:
Senior Member
On Nov 8, 4:08 pm, Mason Barge <masonba...@gmail.com> wrote:
> I'm creating a quiz using PHP 5.3 and MySQL (mysqli).  The database has
> about 1000 questions and answers, in categories, and I want to ask 12
> randomly selected questions, one at a time.
>
> Which would be more efficient:
>
> 1) Make one call to the database and build an array, stored in session
> variables, of 12 randomly chosen rows;  or
>
> 2) Make 12 requests to the database?
>
> I'm open to other general approaches if anyone has a suggestion I haven't
> considered.
>
> I'd like to avoid reloading the page after every answer and I don't see
> how I could use Ajax with #1.  The quiz has to be in PHP because I need to
> generate the final score as a PHP variable, not a javascript variable.

In #1 you can have the query return 12 randomly selected rows.

Regardless of which method you choose, you would store the state
information in a session variable and thus whether you use AJAX or not
is irrelevant.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: how to retrieve xml data from three tables of mysql
Next Topic: Cronjob Apache module v CGI
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 23:54:32 GMT 2024

Total time taken to generate the page: 0.04319 seconds