jeudi 30 août 2018

Storing multiple services and related activity with related periodicity

PHP

<form action="page5_form.php" method="post" name= "test">
  <ul>
    <li>
      <input name='arr[<?php echo $i?>][service]' type='checkbox' data-id='Incometax'value="<?php echo $service['service_id']?>"/><?php echo $service['servicename']?>

      <ol>
           <li>
               <?php foreach ($activities as $activity) : ?>

          <input type='checkbox' name='arr[<?php echo $i?>][activity][]' value="<?php echo $activity['id']?>" /><?php echo $activity['nameofactivity'];?>

          </li>
          <li>
               <?php foreach ($pers as $per) : ?>

          <input type='checkbox' name='arr[<?php echo $i?>][timeperiod][]' value="<?php echo $per['periodicity_id'];?>" /><?php echo $per['per_time'];?>

           </li>
           <br>
      <?php endforeach;?>
        <br>
            <?php endforeach;?>
            <br>



      </ol>

    </li>


    </ul>     


     <?php 
$i++;
    endforeach;?>


      <input name="number" type="hidden" value="<?php echo $next; ?>">

      <input type="submit" name="submit" value="Submit"/>


</form>

Output of my php code is :-

  • GST
    • Return
      • Monthly
      • Yearly
    • Revised
      • Monthly
      • Yearly
      • Quartly
  • Incomtax
    • Application
      • Monthly
      • yearly
    • Return
      • Monthly
      • Yearly

In this output

  1. Incometax and Gst are services.
  2. Return,revised are the activities of service 1 GST and application,Return are the activities of service 2 Incometax.
  3. Monthly,yearly,quartely are the period time of activity.

When I stored this services,My code for storage is

foreach($_POST['arr'] as $input)
 {
  $service = $input['service'];
  echo $service;
  echo "<br>";
  foreach($input['activity'] as $act)
  {
    $query2 = "insert into serviceactmap(client_id,service_id,activity_id)values('$firmid','$servicevalue','$activityvalue')";


    foreach($input['timeperiod'] as $per)
    {



    $query3 = "insert into mapactivityperodicity(client_id,activity_id,perodicity_id)values('$firmid','$activityvalue','$period')";

    }
  }
 } 

  1. I store services and activity in Serviceactivitymap table and activity and periodicity in activitypermap table
  2. When I store in activitypermap table, when I check 1st activity and 1,2 periodicity and 2nd activity and 1 periodicity then it store in db like 1st activity in activity id but 1,2,2 periodicity in per_id.
  3. When I select periodicity in any activity then all the values of periodicity repeated for all activity

Thank u




Aucun commentaire:

Enregistrer un commentaire