title: how to post data from php while loop with ajax
body: <p>I am trying to create a friend button like fb.I have a while loop that echos the name and some other data i need to save into a table in my database for every user request seperatly.My problem is that i don't know how to pass them with ajax because i have same id on textboxes buttons.I tried to pass them with same ids but this passed 3 times the same data or only one of them.So i tried to use the id="something$row[id]" to define every textbox and button but i don't know how to trigger the jquery function and post them with ajax.<a href="http://i.stack.imgur.com/ahQjr.png" rel="nofollow">a picture of what i am trying</a></p>
  
  <blockquote>
    <p>my php file</p>
  </blockquote>
  
  <pre><code>    echo    "&lt;div class='col-xs-12'&gt;
                          &lt;div class='row fixed-table'&gt;
                              &lt;div class='table-content'&gt;
                                  &lt;table class='table table-striped text-muted' id='mytable'&gt;
                                      &lt;tbody&gt;";
                                          while($row = mysqli_fetch_array($requests)){
                                              $username=("SELECT * FROM users WHERE user_id=".$row['patient']);
                                              $found=mysqli_fetch_array(mysqli_query($sql_link,$username));
                                              echo "&lt;tr&gt;
                                                  &lt;td class='text-center'&gt;
                                                      &lt;p&gt;
                                                          $found[username] 
                                                      &lt;p&gt;                                                             
                                                  &lt;/td&gt;
                                                  &lt;td class='text-center'&gt;";
                                                      $patient_username=$found['username'];
                                                      $patient_id=$found['user_id'];
                                                  echo"&lt;input type='text' id='patient_id$row[id]'  class='hidden' value='$patient_id'&gt;
                                                      &lt;input type='text' id='patient_username$row[id]'  class='hidden' value='$patient_username'&gt;
                                                      &lt;input type='text' id='doctor_id$row[id]'  class='hidden' value='$doctor_id'&gt;
                                                      &lt;input type='text' id='doctor_fname$row[id]'  class='hidden' value='$doctor_fname'&gt;
                                                      &lt;input type='button' id='accept_btn$row[id]' class='btn btn-primary' value='Accept'&gt;                                                                                                                                                            
                                                  &lt;/td&gt;
                                              &lt;/tr&gt;";
                                          }
                                      echo "&lt;/tbody&gt;
                                  &lt;/table&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;";
  </code></pre>
  
  <blockquote>
    <p>my js file</p>
  </blockquote>
  
  <pre><code>function decision(){
          var patient_id = $('#patient_id').val();
          var patient_username = $('#patient_username').val();
          var doctor_id = $('#doctor_id').val();
          var doctor_fname = $('#doctor_fname').val();
  
              $.ajax({
                  type:"post",
                  url:"php/add.php",
                  data: {"patient_id": patient_id,"patient_username": patient_username,"doctor_id": doctor_id,"doctor_fname": doctor_fname},
                  success:function(data){
                      $("#decision").html(data);
                  }
              });
  
  $('#accept_btn').click(function(){
          decision();
      });
  </code></pre>