首页 > 解决方案 > 存储服务与活动和周期性相互关联

问题描述

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);
            }


        }



    }
}
?>

在我的代码中,当我选择任何服务和活动时,服务和活动会正确存储,但是当我选择与任何活动相关的任何时间段时,所有选定的活动都会重复所有活动

例如

  1. 当我选择任何 TDS ->25form->monthly,qurterly
  2. 和TDS->31降低扣除申请->monthly,yearly

然后我的输出是

我的预期输出是

标签: phphtmlsql

解决方案


推荐阅读