php - 存储服务与活动和周期性相互关联
问题描述
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);
}
}
}
}
?>
在我的代码中,当我选择任何服务和活动时,服务和活动会正确存储,但是当我选择与任何活动相关的任何时间段时,所有选定的活动都会重复所有活动
例如
- 当我选择任何 TDS ->25form->monthly,qurterly
- 和TDS->31降低扣除申请->monthly,yearly
然后我的输出是
- TDS->25form->每月、每季度、每月、每年
- TDS->降低扣除申请->每月、每季度、每月、每年
我的预期输出是
- Tds->25form->monthly->25form->qurterly
- Tds->降低扣除申请->每月->降低扣除申请->每年
解决方案
推荐阅读
- spring - 具有一个实体的两列的 Spring Boot Data JPA 方法
- android - Android - 默认情况下折叠通知操作
- gradle - 如何使用 Junit5 和 Jacoco 配置 build.gradle 以进行测试覆盖
- python - python import pymssql:未加载库:libsybdb.5.dylib
- c++ - 在 SPOJ 上出现运行时错误(SIGSEGV),无法找出我的代码有什么问题
- python - 通过分组值创建新列的最佳方法是什么?
- python-3.8 - 我想使用用户输入(字符)使用 python 更改文本文件中的第 35 个字符
- java - 如何编写一个java for循环来加载给定一组id和值列表的地图
- javascript - 为什么这段代码不起作用?我正在创建一个 Firefox 扩展,但代码没有运行。但是,如果我将代码粘贴到控制台中,它就可以工作
- angular - 如何在jspdf中对齐图像