zohaib_yii
(Zhshahab)
December 23, 2013, 11:08am
1
<?php echo $form->labelEx($ItemAttribute,'attribute_id'); ?>
<?php echo $form->dropDownList($ItemAttribute, '[]attribute_id', array('empty'=>'Select Attribute')+CHtml::listData(Attribute::model()->findAll(), 'attribute_id', 'name')); ?>
<?php echo $form->error($ItemAttribute,'attribute_id'); ?>
<?php echo $form->labelEx($ItemAttribute,'text'); ?>
<?php echo $form->textField($ItemAttribute,'[]text',array()); ?>
<?php echo $form->error($ItemAttribute,'text'); ?>
<?php echo $form->labelEx($ItemAttribute,'value'); ?>
<?php echo $form->textField($ItemAttribute,'[]value',array('size'=>32,'maxlength'=>32)); ?>
<?php echo $form->error($ItemAttribute,'value'); ?>
this is my code its repeating many time means i am getting these 3 values multiple times from user. but in controller i am unable to insert these although the array is creating…please help me quickly…
richmest
(Richard Mestetsky)
December 23, 2013, 12:45pm
2
I am not sure how you want these arrays to be inserted. If you want them inserted indivually, the usual method would be to loop through the array inserting on each iteration. If you want to combine them, you could join() them into a single string.
How did you code the action in the controller?
THanks for reply now i have done it using this method
$cnt = count($_POST['ItemAttribute']['attribute_id']);
$item_id = $model->item_id;
for($i=0;$i<$cnt;$i++)
{
// $ItemAttribute->item_id = $model->item_id;
// $ItemAttribute->attribute_id =$_POST['ItemAttribute']['attribute_id'];
$sql="INSERT INTO tbl_item_attribute (attribute_id,item_id,text,value) VALUES('".$_POST['ItemAttribute']['attribute_id'][$i]."','".$item_id."','".$_POST['ItemAttribute']['text'][$i]."','".$_POST['ItemAttribute']['value'][$i]."')";
Yii::app()->db->createCommand($sql)->execute();
//
}