title: How to get rid from the same id in while loop when submitting form using ajax
body: <p>I am submitting form using ajax in the while loop but because of loop the same form id is using many times , so as a result the form is submitting only once . I think i have to make unique id every time in the loop for the form but don't know how. </p>
  
  <p>Here is my code so far,</p>
  
  <pre><code>&lt;?php
  $get_cmt ="SELECT * FROM comments WHERE post_id = $post_id ORDER BY id DESC";
  $query_cmt = mysqli_query($db_conx,$get_cmt);
  while($row_cmt=mysqli_fetch_array($query_cmt,MYSQLI_ASSOC)){
  $comtr_id = $row_cmt['comtr_id'];
  $comment_id = $row_cmt['id'];
  ?&gt;
              &lt;form id="subcmt_smt" method="post"&gt;
              &lt;textarea name="subcmt"&gt;&lt;/textarea&gt;
              &lt;input type="hidden" value="&lt;?php echo $comment_id;?&gt;" name="comment_id"&gt;
              &lt;input type="hidden" value="&lt;?php echo $pager_id;?&gt;" name="comtr_id"&gt;  
              &lt;/form&gt;
  &lt;?php } ?&gt;
  &lt;script src="jQuery v2.1.1"&gt;&lt;/script&gt;
  &lt;script&gt;
  $("#subcmt_smt").submit(function(e) {
              var form = $(this);
              var url = form.attr('action');
              e.preventDefault(); 
               $.ajax({
               type: "POST",
               url: "submit_subcmt.php",
               data: form.serialize(), // serializes the form's elements.
               success: function(data)
              {
               alert(data); // show response from the php script.
              }
          });
        });
   &lt;/script&gt;
  </code></pre>
  
  <p>submit_subcmt.php</p>
  
  <pre><code>&lt;?php
  $comtr_id =$_POST['comtr_id'];
  $comment_id =$_POST['comment_id'];
  echo $comtr_id;
  echo $comment_id;
  ?&gt;
  </code></pre>