title: How to apply validation for the Fetched data in php?
body: <p>I have a program which output's a 3 group of Fields from the stored data in the database.<br>
  I able to print it using the for loop but the validation is only for the 1st group field and the other rest 2 group of Fields are not validated.</p>
  
  <p>Below is the code and screen shot of my progam.</p>
  
  <p><em>edit.php</em></p>
  
  <pre><code>&lt;?php for($q=0;$q&lt;count($arr_search['response'][0]['add_info']);$q++){?&gt;
  
  &lt;div class="present_fields_1"&gt;
  &lt;!-- Select Basic --&gt;
  &lt;div class="form-group"&gt;
    &lt;label class="col-md-4 control-label" for="selectbasic"&gt;Type of work:&lt;/label&gt;
    &lt;div class="col-md-4"&gt;
      &lt;select id="type_of_work[]" name="type_of_work[]" class="form-control" style="width: 70%;"&gt;
        &lt;option value="Audit Report"&gt;Audit Report&lt;/option&gt;
        &lt;option value="ITR filing"&gt;ITR filing&lt;/option&gt;
        &lt;option value="VAT Filing"&gt;VAT Filing&lt;/option&gt;
        &lt;option value="Accounting"&gt;Accounting&lt;/option&gt;
        &lt;option value="Registration"&gt;Registration&lt;/option&gt;
        &lt;option value="Certification"&gt;Certification&lt;/option&gt;
        &lt;option value="Others"&gt;Others&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- Select Basic --&gt;
  &lt;div class="form-group"&gt;
    &lt;label class="col-md-4 control-label" for="selectbasic"&gt;Status:&lt;/label&gt;
    &lt;div class="col-md-4"&gt;
      &lt;select id="status" name="status[]" class="form-control" style="width: 70%;"&gt;
        &lt;option value="&lt;?php echo $arr_search['response'][0]['add_info'][$q]['status']; ?&gt;"&gt;&lt;?php echo $arr_search['response'][0]['add_info'][$q]['status']; ?&gt;&lt;/option&gt;
        &lt;option value="Pending"&gt;Pending&lt;/option&gt;
        &lt;option value="Work in process"&gt;Work in process&lt;/option&gt;
        &lt;option value="Completed"&gt;Completed&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;!--date--&gt;
  &lt;div class="form-group row"&gt;
    &lt;label for="example-date-input" class="col-2 col-form-label" style="margin-left:28.5%;"&gt;DATE:&lt;/label&gt;
    &lt;div class="col-10"&gt;
      &lt;input class="form-control datepicker p" id="date[]" name="date[]" value="&lt;?php echo $arr_search['response'][0]['add_info'][$q]['date']; ?&gt;"   type="text" readonly style="width: 70%;"&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;!-- Text input--&gt;
  &lt;div class="form-group"&gt;
    &lt;label class="col-md-4 control-label" for="textinput"&gt;Comment:&lt;/label&gt;  
    &lt;div class="col-md-4"&gt;
    &lt;input id="commentss" name="comment[]" value="&lt;?php echo $arr_search['response'][0]['add_info'][$q]['comment']; ?&gt;" type="text" placeholder="" class="form-control input-md" style="width: 70%;" &gt;
  
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;a href="#" class="remove_field_pre1" style=""&gt;
   &lt;img src="images/del24.png"&gt;
  &lt;/a&gt;
  
  &lt;/div&gt;
  
  
  &lt;?php  }?&gt;
  
  &lt;script type="text/javascript"&gt;
   $(document).ready(function () {
          $("#status").click(function () {
  
              if ($("#status").val() == "Completed") {
                  $("#commentss").attr("required", "required");
              }
              else
                $("#commentss").attr("required", false);
          });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>As you can see that, the last part of the code i.e, Javascript is only apply to the 1st group and not the remaining part of the code.</p>
  
  <p>This is the ScreenShot <a href="https://i.stack.imgur.com/onwyt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/onwyt.png" alt="ScreenShot"></a></p>