Checkbox using data from database

Hi!

I need help in this particular check box option. How can i create a checkbox function which the value taken from the database? i assumed array is used in this type of function, but i do not know how to do the codings for it…

1 table which is the Programme, have several checkbox which is named Programme Objectives.

so the details of the programme objectives i have put in another table which is called Ref_Prog_Objectives.





		<?php echo $form->labelEx($model,'PROG_OBJECTIVES'); ?>

		<?php //ni this is for dropdown which takes reference from REF_PROG_TYPE table in database?>

		

		<?php echo $form->dropDownList($model,'PROG_OBJECTIVES',CHtml::listData(REFPROGOBJ::model()->findAll(),'ID','DESC'), array('prompt' => 'Select Program Objectives')); ?>  //this one is dropDownList, but this is not what i want to do because i want to create a checkbox to make this programme objectives to be more than 1 objective.

		

		<?php echo $form->error($model,'PROG_OBJECTIVES'); ?>

		




i am very sorry for my poor english. and thank you in advance.

Maybe $form->checkBoxList is what you are looking for?

Hi there… I think so, thanks…

If you want the checkboxes to keep their values after gridview pagination, check out this post:

Retain Checkbox Value

If your gridview is part of a form (using data from the db) and you want the checkboxes to keep their values after form submission, check the "Also make this work on normal form submit" answer on the same post.

<?php

$radioCC = array(‘separator’=>’’,‘template’=>’<div class=“c-checkbox col-lg-4 col-md-6 col-sm-6 col-xs-12 m0”>{input}{label}</div>’);

echo $activeform->checkBoxList($profile, ‘department[]’,

CHtml::listData(Department::model()->findAll($deptCrietarea),‘id’,‘title’),$radioCC );

?&gt;

Here departments will be loaded from department model and by using listdata() a list with parent-key relation passed to checkboxlist