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 #170589 is a reply to message #170570] Tue, 09 November 2010 09:48 Go to previous messageGo to previous message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma:
Senior Member
On 11/8/2010 7:52 PM, Mason Barge wrote:
> On Mon, 8 Nov 2010 11:45:16 -0500, "Matthew Leonhardt"
> <matt(at)mattleonhardtmusic(dot)com> wrote:
>
>> "Mason Barge"<masonbarge(at)gmail(dot)com> wrote in message
>> news:s87gd61ldtnkeuuc817uiej2qmv0s4vc88(at)4ax(dot)com...
>>> 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
>>
>> Most likely this method. You're talking about a fairly small amount of data
>> though, so I highly doubt you need to be worried about efficiency...
>>
>>> 2) Make 12 requests to the database?
>>>
>>> I'm open to other general approaches if anyone has a suggestion I haven't
>>> considered.
>>
>> You could also opt for a hybrid solution...generate a session array
>> containing 12 primary keys and then with each page load, just pop the next
>> question, so to speak :)
>
> Yeah that's what I'd do.
>
>>> 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.
>>
>> I don't see how #1 prevents an AJAX solution. What's your cause for worry
>> about that? Regarding the language in which the final score is calculated,
>> look at json_encode() and json_decode() for convenient data-passing between
>> the two languages.
>>
>
> Thanks so much, I've been out of touch with PHP for a long time and didn't
> know about JSON. It solves so many problems with this kind of thing.

Hi Mason Barge,

I don't want to be too negative, but you exaggerate things.
JSon is just a dataformat definition to exchange data.

You have *your* serverside PHP scripts, and *your* JavaScript in the
browser.
So you might as well make up your own format and use that. ;-)
I don't see how JSON is solving so many problems for you.

Regards,
Erwin Moller


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
[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:48:14 GMT 2024

Total time taken to generate the page: 0.04509 seconds