Insert Data To A Table From Two Non-Related Tables

Hi All,

I have only two weeks experience in yii.

My situation is like this.

I have three tables student, class and attendance. student and class tables are not related, But attendance table contain student_id and class_id.

I want to create a view to select attended students to a selected class as follows;

  1. Select a class from list. ( Table: class)

  2. Select students by checkbox list.( Table: Student)

  3. Update the attendance table by class_id and selected student_ids.

  4. Avoid duplication of class_id, student_id combination in attendance table.

It’s really appreciate any help to create relevant MVC pages.

So far I checked following pages, but still failed to solve the situation.

http://www.yiiframework.com/doc/guide/1.1/en/database.ar

yiiframework.ru/doc/guide/en/database.arr

http://www.yiiframework.com/forum/index.php/topic/35072-cgridview-with-ccheckboxcolumn/page__p__168655__fromsearch__1#entry168655

Thanks for any support.

That’s MANY_MANY relation ( http://www.yiiframework.com/doc/guide/1.1/en/database.arr#declaring-relationship )

Unfortunately, Yii itself cannot store MANY_MANY, but there are a lot of extensions

http://www.yiiframework.com/extensions/?tag=MANY_MANY

Dear Orey,

Thank you very much for the quick reply.

I tried to use the extension multimodelforms before. It didn’t meet with my requirements.

I never thought about such a big list of extensions until your suggestion. Thanks for that and I’ll try them.

Actually my biggest problem is, " How to post (from view) and get (in controller) two data columns. ( class_id is only one record while student_id will be more than one at a time).

Check out this post on how to display many-many checkboxes. This technique uses cadvancedarbehavior.

Matt

Thank you very much.

This is a life saver. Worked like charm.

Another two questions:

  1. How to add an extra column to checkbox list ( Eg: Name,Gender)?

  2. Can’t we do pagination and search for this checbox list?