In my experience, it is a bit awkward to do this using SQLFORM.  You
could try something like this:

db.define_table('q_and_a',
    Field('question'),
    Field('answer'))

rows = db(db.q_and_a.id>0).select()

import random
random.seed()
asked = random.sample(rows, 3))

form=SQLFORM.factory(
    Field('asked_0', label = asked [0]['question']),
    Field('asked_1 ', label = asked [1]['question']),
    Field('asked_2 ', label = asked [2]['question']))


But this can create more problems than it solves.  Ultimately it might
be easier to put your questions in a wide table and use something like
Massimo proposed here:

http://groups.google.com/group/web2py/browse_thread/thread/d0093fa1901b565e/ca664f76800cfbd7



On Aug 20, 1:10 pm, dlin <dlin...@gmail.com> wrote:
> Tks, Bruno.
> I seems haven't describe the 'row base' questionaire.
>
> That is:
>
> I've already a table like:
> Question Answer
> Q1...           A1
> Q2...           A2
> Q3...           A3
> ...
> Q13...           A1
>
> Then, I'll random choose three(or by customized) questions to ask.
>
> Question  Answer
> Q3.....      ____
> Q8.....      ____
> Q9.....      ____
>  [submit]
>
> sometimes, it
> Question  Answer
> Q7.....      ____
> Q9.....      ____
> Q13.....      ____
>  [submit]
>
> I think it is not proper to save it fixed on 3 field on table.
>
> I'm thinking should I use following steps:
> 1. SQLTABLE to select some random rows from my question and answer .
> 2. try to form a FORM() (I haven't idea now)
> 3. when user submit form, then try to compare the answer and store the
> scores of user in another table.
>
> On Aug 19, 7:54 am, Bruno Rocha <rochacbr...@gmail.com> wrote:
>
> > You can use FORM(), and also use the table configuration to define
> > questions,
> > you can use the arguments "label" and "comment" on field definition.
>
> > After that, you can use CSS to improve the form layout.
>
> > You can't create a new field to store the login info and putting by default
> > the auth.user value?
>
> > 2010/8/18 dlin <dlin...@gmail.com>
>
> > > I want a form like:
>
> > > Question  Answer
> > > Q1.....      ____
> > > Q2.....      ____
> > > Q3.....      ____
> > > [submit]
>
> > > Q1,Q2,Q3 and correct answer is stored in a table.
> > > But the 'Answer' field should combined with login user's answer.
>
> > > What's the best way to display the form to user?
> > > Do you suggest use FORM() in control or use <form> in view?
>
> > --
>
> >http://rochacbruno.com.br

Reply via email to