I'm making some app (admin page), I loaded all users in <table>, also I have option to activate and deactivate each user. Now my problem is I don't know how to detect which 'activate' or 'deactivate' button is pressed, my code only works for first user in list. This is my code:
adminPage.php:
<?php
$getData = $mysqli->query("select * from login");
while($row = $getData->fetch_assoc()):
?>
<tr id="dataRows">
<td id="firstTd"><?php echo $row['user_id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['active']; ?></td>
<?php if($row['active'] == 1){ ?>
<td><label id="userID" hidden><?php echo $row['user_id']; ?></label>
<label id="userActive" hidden><?php echo $row['active']; ?></label>
<label id="optionLabel"><?php echo 'Deactivate'; ?></label></td>
<?php } else{ ?>
<td><label id="userID" hidden><?php echo $row['user_id']; ?></label>
<label id="userActive" hidden><?php echo $row['active']; ?></label>
<label id="optionLabel"><?php echo 'Activate'; ?></label></td>
<?php } endwhile; ?>
script.js:
$("#optionLabel").click(function(){
$.post("option.php", {"id" : $("#userID").html(), "com" : $("#userActive").html()},
function(data){
if(data == "Updated"){
window.location.href = "adminPage.php";
}
}
);
});