I have a site with database.
I create an HTML table with the content from database with success.
Now I want each element in the table to be an anchor and open a modal with the information in the database for the element I clicked.
It's working, the only problem is that only the first modal will open no matter which element is clicked.
If I click on the 3rd element, it will show the information on the first.
In the image, I click on Mike, and it shows me William Soares(first)
<div class="col-sm-4"><div class="table-responsive" style="margin: 1%">
<h3 style="color: white; font-weight: bold; font-style:italic;">Defesas</h3>
<table class="table table-dark">
<thead>
<tr>
<th>Numero</th>
<th>Nome</th>
</tr>
</thead>
<tbody>
<?php
$sql = 'SELECT * FROM jogadores ORDER BY id ASC LIMIT 32';
$stmt = $dbh->prepare( $sql );
$stmt->execute();
if( $stmt && $stmt->rowCount() > 0)
{
while( $obj = $stmt->fetchObject() )
{ if ($obj->posicao == "Defesa") {
?>
<tr>
<th><?php echo $obj->numero_camisola ?></th>
<td><a href="#modalJog" data-target="#modalJog" data-toggle="modal">
<?php echo $obj->nome ?></a>
<div id="modalJog" class="modal fade" role="dialog" >
<div class="modal-dialog">
<div class="modal-content" style="background-color: black;">
<div class="modal-header">
<h5 class="modal-title"><?php echo $obj ->nome ?></h5>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<p><?php echo $obj ->nomeCompleto?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
<?php
}
}
}
else
echo 'N?o existem jogos disponíveis.';
?>
</table>
</div></div>
</div>
https://ibb.co/r0DbwnF
https://ibb.co/tcQpNWy
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…