How To Create Form Like Exam Page

hello… this is my first post.

help me please.

i have 2 tables "question" and "answer" in mysql database.


mysql> desc question;

+----------+---------+------+-----+---------+----------------+

| Field    | Type    | Null | Key | Default | Extra          |

+----------+---------+------+-----+---------+----------------+

| id       | int(11) | NO   | PRI | NULL    | auto_increment |

| question | text    | NO   |     | NULL    |                |

+----------+---------+------+-----+---------+----------------+

2 rows in set (0.01 sec)


mysql> desc answer;

+-------------+---------+------+-----+---------+----------------+

| Field       | Type    | Null | Key | Default | Extra          |

+-------------+---------+------+-----+---------+----------------+

| id          | int(11) | NO   | PRI | NULL    | auto_increment |

| question_id | int(11) | NO   | MUL | NULL    |                |

| answer      | text    | YES  |     | NULL    |                |

+-------------+---------+------+-----+---------+----------------+

3 rows in set (0.01 sec)

question_id on table answer referenced to id in table question.

i created the crud for model Answer i got this form create.

but with this form it is not looks good for exam page.

4554

Capture.JPG

how do i create form with questions on left column and answer column on right in 1 form input?

questions are auto filled and get from table question.

i have tried tutorial "How to use single form to collect data for two or more models (CActiveForm and Ajax Validation edition)" but i just got error.

please help.

thanks a lot …

pass the two models to the view that u want to show. put all the result sections inside a form.

note: each answer need new instance of the model Answer

and

what is the error ?

hello… i got error in how to pass models to the view, but now it resolved. thank you.

i have passed 2 models to the view. the question table on database has a 10 question. so this is i got from CRUD.

4555

Capture.JPG

i want to display all question and answer column follow on how many questions are displayed. i want manage this page like a exam page.

4556

Capture.JPG

is it possible to achieve using Yii?

thank you in advanced.

as array

yes use attribute as question_id[], and answer[], then u will get a 2d array

use your logic,

inside the questions loop

display qn

next

use attribute answer[‘question_id here’], then u will get a 2d array with qn id as key.