HTML
<form action="htmlindex.php" method = "post">
<input type="checkbox" name="arr[1][service]" value="Income tax" id="service-1" >
1Income tax
<br>
<div class="service_options_1" style="display: none;">
<input type="checkbox" name="arr[1][activity][]" value="Return Filing
">1Return Filing
<br>
<input type="checkbox" name="arr[1][timeperiod][]" value="monthly">monthly
<input type="checkbox" name="arr[1][timeperiod][]" value="Quarterly
">Quarterly
<br>
<input type="checkbox" name="arr[1][activity][]" value="Revised Return Filing
">2Revised Return Filing
<br><input type="checkbox" name="arr[1][timeperiod][]" value="monthly">monthly<input type="checkbox" name="arr[1][timeperiod][]" value="Quarterly
">Quarterly
</div>
<br>
<input type="checkbox" name="arr[2][service]" value="TDS" id="service-2" >
2TDS
<br>
<div class="service_options_2" style="display: none;">
<input type="checkbox" name="arr[2][activity][]" value="25form
">25Form
<br>
<input type="checkbox" name="arr[2][timeperiod][]" value="monthly">monthly
<input type="checkbox" name="arr[2][timeperiod][]" value="Quarterly
">Quarterly
<br>
<input type="checkbox" name="arr[2][activity][]" value="Department Vist
">26Department Vist
<br>
<input type="checkbox" name="arr[2][timeperiod][]" value="monthly">monthly
<input type="checkbox" name="arr[2][timeperiod][]" value="Quarterly
">Quarterly
<br>
<input type="checkbox" name="arr[2][activity][]" value="Lower Deduction Application
">31Lower Deduction Application
<br><input type="checkbox" name="arr[2][timeperiod][]" value="monthly">monthly<input type="checkbox" name="arr[2][timeperiod][]" value="Quarterly
">Quarterly
<input type="checkbox" name="arr[2][timeperiod][]" value="Yearly
">Yearly
<input type="checkbox" name="arr[2][timeperiod][]" value="Random">Random<br>
</div>
<br>
<input type="checkbox" name="arr[3][service]" value="GST" id="service-3" >
3GST
<br>
<div class="service_options_3" style="display: none;">
<input type="checkbox" name="arr[3][activity][]" value="Tax Payment
">29LUT Application
<br><input type="checkbox" name="arr[3][timeperiod][]" value="monthly">monthly
<input type="checkbox" name="arr[3][timeperiod][]" value="Quarterly
">Quarterly
<input type="checkbox" name="arr[3][timeperiod][]" value="Yearly
">Yearly
<input type="checkbox" name="arr[3][timeperiod][]" value="Random">Random<br><br>
</div>
<br>
<input type ="hidden" name="serviceactivity">
<input type="submit" name="submit" value="Submit">
</form>
当我显示或存储相关活动或时间段时,我选择的所有活动重复的时间段
我用于存储或显示数据的代码是
<?php
if(isset($_POST['submit']))
{
foreach($_POST['arr'] as $input)
{
$ser = $input['service'];
foreach($input['activity'] as $act)
{
$query = "insert into serviceactmap(service,activity)values('$ser','$act')";
$conn->query($query);
foreach($input['timeperiod'] as $time)
{
$sql = "insert into acttimemap(activity,timepriod)values('$act','$time')";
$conn->query($sql);
}
}
}
}
?>
在我的代码中,当我选择任何服务和活动时,服务和活动将正确存储,但是当我选择与任何活动相关的任何时间段时,对于所有活动重复所有选定的活动
例如
然后我的输出是
我的预期输出是