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>
When I display or store related activity or timeperiod then timeperiods which I select repeated for all selected activity
My code for store or display data is
<?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);
}
}
}
}
?>
In my code when I select any service and activity then service and activity store properly but when I select any timeperiod related to any activity then all selected activity repeated for all activity
for example
Then My output is
My expected output is