Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php插入数组类型复选框和文本_Php_Mysql_Codeigniter - Fatal编程技术网

使用php插入数组类型复选框和文本

使用php插入数组类型复选框和文本,php,mysql,codeigniter,Php,Mysql,Codeigniter,如何使用php codeigniter从复选框插入数组数据并输入文本 这是我的看法 <?php foreach ($data_ikan as $row) { ?> <tr> <td> <div class="form-check"> <input class="form-check-input" type="checkbox" name="ikan[]" value="<?php echo $row['nama_ikan']; ?&

如何使用php codeigniter从复选框插入数组数据并输入文本

这是我的看法

 <?php foreach ($data_ikan as $row) { ?>
<tr>
 <td>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="ikan[]" value="<?php echo $row['nama_ikan']; ?>" id="checkbox<?php echo $row['id_data_ikan']; ?>">
<label class="form-check-label" for="checkbox<?php echo $row['id_data_ikan']; ?>">
<?php echo $row['nama_ikan']; ?>
</label>
</div>
</td>
<td>
<input type="number" name="produksi[]" class="form-control form-input-sm my-1" id="produksi<?php echo $row['id_data_ikan'] ?>" placeholder="Kg" disabled>
</td>
</tr>
<?php } ?>

用于复选框

$checkboxes = $_POST["ikan[]"];
然后你可以循环通过它

foreach($checkboxes as $checkbox){
   //code
}
请试试这个:

<?php foreach ($data_ikan as $row) { ?>
<tr>
<td>
<input class="form-check-input" onclick="return show('<?=$row['id_data_ikan']?>')" type="checkbox" name="ikan[]" value="<?=$row['id_data_ikan']?>" id="checkbox<?=$row['id_data_ikan']?>"><?=$row['nama_ikan']?>
</td>
<td>
<input type="number" name="produksi<?=$row['id_data_ikan']?>" class="form-control form-input-sm my-1" id="produksi<?=$row['id_data_ikan']?>" placeholder="Kg" disabled>
</td>
</tr>
<?php } ?>


输入型文本怎么样??我想把两者都插进去。可以是foreach循环吗?可以,你有没有尝试过这个复选框?我想同时插入复选框和文本,但我不知道如何保存数组和插入数据库。如果数据只是复选框,我可以将其插入数据库,但我需要复选框和输入文本这可能对您有所帮助。mau masukan data checkbox sama form input text itu ke db mas,cuma ga tau logika insert nya karena bentuk array。如果是复选框列表,则表单输入不会禁用变量复选框,因为输入文本可能不正确。杨炳坤cuma插入数组ke数据库Nya。这是一个数组[“ikan”]=>数组(2){[0]=>string(3)“aaa”[1]=>string(4)“GGGGGG”}[“produksi”]=>数组(2){[0]=>string(2)“12”[1]=>string(2)“15”}coba-ikuti link@Dum,permasalahanya-cuman-insert-ke-ke-ke-table-kan,1 id-pesan banyak-ikan-and-jumlah-produksi-kan??用数组映射解决了这个问题:)
<script>
function show(id) {
  if(document.getElementById('checkbox'+id).checked){
    document.getElementById("produksi"+id).disabled = false;
  }else{
    document.getElementById("produksi"+id).disabled = true;
  }
}
</script>