I have a foreach that prints the data from my database in PHP. I got a link for every of these rows that allow me to delete each data from database. Right under foreach I got a input type="hidden" with the ID of the data as value.
<?php
foreach($sql->query("SELECT * FROM table") AS $row) {
<input type="hidden" value="'.(int)$row['id'].'">
echo $row['name'].' (<a href="javascript:void(0)" id="delete-row">delete</a>)';
}
?>
After some intense Google searches I came up with this. But when I click on the “delete” link it prints every single row in the loop with this code.
$(document).ready(function() {
$('#delete-row').click(function() {
var val = $('input[type="hidden"]').map(function() {
return this.value;
}).get();
alert(val);
});
});
This is wrong! I want to get the ID for that link I click on. If I click on the link with ID 3 it shall alert me with ID 3. Do you know how I can fix my problem?
Thanks in advance.
I would not even use a hidden field for this.