Notice that every modal trigger button has adata-target
attribute to define which modal will be opened.
In your case, the button of every row you used to triggered the modal have the samedata-target
, which is#confirmDelete
. These modals behind also has the sameid
called#confirmDelete
, so every time you hit the modal trigger button (all had the samedata-target
) then eventually it will shows up the very first modal element.
For a better understanding, compare my code to yours and see the differences.
<?php foreach ($utenti as $utente) { ?>
<tr>
<th scope="row"> <?php echo $utente['idUser']?> </th>
<td><?php echo $utente['nome']." ".$utente['cognome']?></td>
<?php if($_SESSION['role'] == 1) {?>
<td><?php echo $utente['az']?></td>
<?php } ?>
<td><?php echo $utente['email']?></td>
<td class="text-warning"><a
href="<?php echo 'editUser.php?user='.$utente['idUser']?>"><i
class="fas fa-edit text-warning"></i></a></td>
<!-- <td class="text-warning"><a href=" "><i class="fas fa-trash-alt text-danger"></i></a></td> -->
<td class="text-danger">
<button type="button" class="btn" data-toggle="modal"
data-target="#confirmDelete_<?php echo $utente['idUser']; ?>"><i
class="fas fa-trash-alt text-danger"></i><?php var_dump($utente['idUser']); ?>
</button>
</td>
<div class="modal" tabindex="-1" role="dialog" id="confirmDelete_<?php echo $utente['idUser']; ?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Attenzione <?php echo $utente['idUser']; ?></h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Continuando eliminerai l'utente in maniera irreversibile</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger "
><a
class="text-white btn-modal-confirm"
href="<?php echo '?action=delete&user='.$utente['idUser']?>"
>Elimina</a>
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Indietro
</button>
</div>
</div>
</div>
</div>
</tr>
<?php }?>
In the above code, I gave every pair of modal elements (modal trigger button and modal ID) a uniquedata-target
value and a unique element id.
...
<button type="button" class="btn" data-toggle="modal"
data-target="#confirmDelete_<?php echo $utente['idUser']; ?>">
...
<div class="modal" tabindex="-1" role="dialog" id="confirmDelete_<?php echo $utente['idUser']; ?>">
...
Now each pair of modal elements have their ownids
and they should be working the way you wanted.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.