Checkboxlist to Save Multiple Records


I am newly use YII. I want to use checkboxlist to save multiple records. For example there is column/field named "order_number" and "service". One "order_number" can have many "services".

So, this is a form example:

Order_number: …


a. …

b. …

c. …

d. …

When I choose order_number (1) and service (a,b,c) click submit/create, I want to save in database like below:

id order_number service

1 1 a

2 1 b

3 1 c

Is there any solution to solve my problem?

I’m no expert in yii, but after googling this over half an hour, I ended up doing it manually.

Basically it would depend on what are you planning to do with the data. It’s either that you combine the whole array into the same variable using implode

$model = new Post();


   $model->attributes = $_POST['Post'];

   $valid = $model->validate();    //<-- I'm just guessing this is how you validate >.<


       $model->yourCheckBoxItems = implode(",",$model->yourCheckBoxItems);



or if you are planning to save the checkbox data to another new row, it would be a little longer, but basically it would have the same logic. Never tested it out yet, but you can try it. Shoot back a message if I’m totally wrong

$model = new Post();


   $model->attributes = $_POST['Post'];

   $valid = $model->validate();    //<-- I'm just guessing this is how you validate >.<


       $tempCount = 0; // needed to ensure the correct index

       $tempData = "";





             $tempData[$tempCount] = $model->yourCheckBox[$i];





          $model->setIsNewRecord(true);  // To make sure that this would add new record and not update

          $model->yourCheckBox = $tempData[$i];




I do think that there are better ways to do it, and I haven’t yet tried out this:

It shows how to delete multiple records, wherein the data to be deleted came from some few check boxes. I think that this could also be used in saving items, I’m not sure though since I never had got the opportunity to try this out, correct me if I’m wrong.

Please follow this articles -


Uninitialized string offset: 0

its displays this abv error, please help me! can i need to attach the code? somebody help?


I am getting a error while select multiple check box and insert into mysql table ,Please somebody Help


Column name must be either a string or an array.[/b][/i][/u]

<---------------------------------- This is the error


816 }

817 if(count($values)===1)

818 {

819 $entries=array();

820 foreach($values[0] as $name=>$value)

821 $entries[]=$prefix.$table->columns[$name]->rawName.($value===null?’ IS NULL’:’=’.$value);

822 return implode(’ AND ',$entries);

823 }


825 return $this->createCompositeInCondition($table,$values,$prefix);

826 }

827 else

828 throw new CDbException(Yii::t(‘yii’,‘Column name must be either a string or an array.’));

829 }


831 /**

832 * Generates the expression for selecting rows with specified composite key values.

833 * @param CDbTableSchema $table the table schema

834 * @param array $values list of primary key values to be selected within

835 * @param string $prefix column prefix (ended with dot)

836 * @return string the expression for selection

837 */

838 protected function createCompositeInCondition($table,$values,$prefix)

839 {

840 $keyNames=array();

/************* THis is FUNCTION of update query*****************/////

public function actionUpdate($id)



	&#036;menumodel = new MenuRoles;

	// Uncomment the following line if AJAX validation is needed

	// &#036;this-&gt;performAjaxValidation(&#036;model);





		//&#036;roleid = &#036;model-&gt;id;


		if(&#036;model-&gt;save()) {



		foreach(&#036;menumodel-&gt;menu_id as &#036;menuid){


				&#036;menumodel-&gt;menu_id = &#036;menuid;

				&#036;menumodel-&gt;role_id = 1;












Same thing in check boxlist.

I want in update case .

Do anyone have idea for it?

This post was helpful