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 picture of what i am trying
my php file
echo "<div class='col-xs-12'>
<div class='row fixed-table'>
<div class='table-content'>
<table class='table table-striped text-muted' id='mytable'>
<tbody>";
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 "<tr>
<td class='text-center'>
<p>
$found[username]
<p>
</td>
<td class='text-center'>";
$patient_username=$found['username'];
$patient_id=$found['user_id'];
echo"<input type='text' id='patient_id$row[id]' class='hidden' value='$patient_id'>
<input type='text' id='patient_username$row[id]' class='hidden' value='$patient_username'>
<input type='text' id='doctor_id$row[id]' class='hidden' value='$doctor_id'>
<input type='text' id='doctor_fname$row[id]' class='hidden' value='$doctor_fname'>
<input type='button' id='accept_btn$row[id]' class='btn btn-primary' value='Accept'>
</td>
</tr>";
}
echo "</tbody>
</table>
</div>
</div>
</div>";
my js file
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();
});