나는 루프로 &이라는 배열에 다른 값을 가진 4 개의 체크 박스를 가지고 있습니다. 마지막 루프 된 체크 박스 세트에서만 선택된 값이 업데이트되고 있지만 선택한 모든 값 (4 세트 당 1 개)이 해당 행에 독립적으로 업데이트되어야합니다.루프 된 체크 박스 배열 값 반복
HTML
<input type="checkbox" name="size[]" value="S" />
<input type="checkbox" name="size[]" value="M" />
<input type="checkbox" name="size[]" value="L" />
<input type="checkbox" name="size[]" value="XL" />
PHP
<?php
if(isset($_POST['update'])){
$select_id = "select * from customer where ip='$ip'";
$get_id = mysqli_query($db, $select_id);
while ($row = mysqli_fetch_array($get_id)){
foreach($_POST['size'] as $size){
$product_id = $row['product_id'];
$update_size = "update customer set size='$size' where product_id='$product_id'";
$run_size = mysqli_query($db, $update_size);
}
}
}
?>
UPDATE - 거의 다! PROCESSING IN
$i++;
<input type="checkbox" name="size[].$i." value="S" />
<input type="checkbox" name="size[].$i." value="M" />
<input type="checkbox" name="size[].$i." value="L" />
<input type="checkbox" name="size[].$i." value="XL" />
가
<?php
if(isset($_POST['update'])){
$select_id = "select * from customer where ip='$ip'";
$get_id = mysqli_query($db, $select_id);
while ($row = mysqli_fetch_array($get_id)){
$size = $_POST['size'];
$product_id = $row['product_id'];
foreach ($size as $_POST['size']);
{
$update_size = "update customer set size='$size' where product_id='$product_id'";
$run_size = mysqli_query($db, $update_size);
}
}
}
?>
그것은 이제 다른 행 당 변수 세트 이제는 하나를 업데이트하는 동안에 루프 while 루프
$i = 1;
OF
가OUT은 올바른 값 , 다른 배열하지만 왜?
죄송 합니다만 하나의 확인란 만 선택되므로 행 당 4 개의 값 중 하나만 저장됩니다. – Steven
체크 박스를 클릭하면' 또는 자바 스크립트를 체크 박스에 추가하여 다른 체크 박스를 체크 해제 할 수 있습니다. 참조는 다음과 같습니다. http://jsfiddle.net/MQM8k/ –
상자의 다음 반복문이 고유 할 수 있도록 확인란의 이름을 증가시켜야합니다. – Steven