Here are the relevant parts of my code. I am using a mysql query to fetch all the info and displaying it in a table. Currently the table displays information of all users which is editable. I want to make it so it displays just the userID, username,..., and than have a button which I can click which will take me to a page where I can update all that individual users information. Each row will have a button that can be clicked
<td data-th="ID">'.$fetch['userID'].'</td>
<td class="userInfo" data-th="Username"id="'.$fetch['userID'].'"key="username">'.$fetch['username'].'</td>
<td class="userInfo" data-th="End" id="'.$fetch['userID'].'" key="end_date">'.$fetch['end_date'].'</td>
Each row will have this button. I want to be able to click it and have it take me to another page where it lists the individual users info so it can be updated. I am unsure of how to get this done. How can I pass the userID of the row of the user I want to update?
<td> <a href="updatemember.php" class="btn btn-secondary btn-lg" role="button">Link</a> </td>
javascript
jQuery(document).ready(function() {
$.fn.editable.defaults.mode = 'popup';
$('.userInfo').editable();
$(document).on('click','.editable-submit',function() {
var col = $(this).closest('.editable-container').prev().attr('key');
var x = $(this).closest('.editable-container').prev().attr('id');
var y = $('.input-sm').val();
var z = $(this).closest('.editable-container').prev().text(y);
$.ajax( {
url: "process.php?id="+x+"&data="+y+'&col='+col,
type: 'GET',
success: function(s){
if(s == 'status') {
$(z).html(y);
}
if(s == 'error') {
alert('Error.');
}
},
error: function(e){
alert('Error.');
}
});
});
});
Code to update each row
$col=$_GET['col'];
$id = $_GET['id'];
$data = $_GET['data'];
$pbr = $conn->prepare("UPDATE `loginInfo` l
INNER JOIN `memberInfo` AS m
ON l.userID = m.UserID
SET $col = '$data'
WHERE m.userID = ?");
$pbr->bind_param("i", $id);
$pbr->execute();
The shortest way is to store id of current record in your tag id. In your php code when you output your table: echo "<a href='...' id='$id' .....>"
And in your jQuery you can get it by id = $(this).attr("id")
in onClick handler.