<?php
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result)) {
echo '<tr><td>';
echo '<h5 style="margin-left:6px; color:black;">' . $row['id'] . '</h5>';
echo '</td><td>';
echo '<img src="'. $row['imagem']. '" alt>';
echo '<a href="#" class="user-link">'. $row['nome'] . '</a>';
echo '</td><td>';
echo '<h5 style="margin-left:-180px; color:black;">'. $row['idaluno'] . '</h5></td>';
echo '<td class="text-center">';
echo '<h5 style="margin-left:6px; color:black; margin-left:-297px;">'. $row['situacao'] .'</h5>';
echo '</td><td>';
echo '<h5 style="margin-left:15px; color:black;">'. $row['faltas'] .'</h5>';
echo '</td><td>';
echo '<a href="editar.php?idaluno='. $row['id'] .'"><i style="margin-left:10px;" class="fa-solid fa-pencil"> </i></a>';
echo '
<button id="myBtn">
<i style="margin-left:10px;" class="fa-solid fa-trash"></i>
</button>';
echo ' </td></tr>';
}
?>
<button id="myBtn">
<i style="margin-left:10px;" class="fa-solid fa-trash"></i>
</button>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
im trying to make a confirmation modal for trying to delete a row in sql, i have php loop the button for each row, but the button doesnt work inside php, i have the button outside the php loop aswell and it works
im new to php and javascript, i think this could be resolved through ajax requests but im lost on that too. please help
1