How to add multiple data into mysql from dynamic checkbox?





			$query="SELECT * from booking_user, booking_roominfo where booking_roominfo.roominfo_userID=booking_user.user_ID and roominfo_ and roominfo_slotID='$y[$k]' and roominfo_roomID='$roomid'";


			while($row= mysql_fetch_array($result))


				echo "<td height='40' bgcolor='#FF3366' style='border:1px solid black'><center>".$row['user_name']."<br></td>";						





			echo "<td height='40' bgcolor='#3399FF' style='border:1px solid black'>".$form->checkBox($model,'roominfo_slotID', array('value' => $k, 'name'=>'checkbox[$k]'))."$slottime[$k]</td>";




how should i add the data into mysql table if multiple checkbox is checked?

p/s: each checkbox represent a row in the tableā€¦

thanks guys.appreciate the helps.

First you are mixing views and controller(model) items in one file, no matter if file from which you pasted code is controller or view.

And answer to your question:



You can find more details here:

Thanks Ivica.I will try see whether my problem is solved or not.

<?php echo $form->hiddenField($model,'roominfo_date',array('value'=>'2011-08-14'));?>

		<?php echo $form->hiddenField($model,'roominfo_userID',array('value'=>Yii::app()->user->id)); ?>

		<?php echo $form->hiddenField($model,'roominfo_roomID',array('value'=>$roomid)); ?>

		<?php foreach($_POST['checkbox'] as $checkbox) 


				echo $form->hiddenField($model,'roominfo_slotID',array('value'=>1));

			  } ?>

<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


actually the problem I face is when I want to get the value from one or more checkbox. How can I save each value of the checkbox per 1 row in the table of mysql?? my checkbox is build dynamically.(e.g. 1 checkbox selected -> 1 data created and stored 1 row in database, 5 checkbox selected -> 5 data created and stored 5 row in database.)