0

So, I want to show detail data from row that I clicked. I clicked from looping data showing in table. here is the code.

$fetchall = "SELECT * FROM data";
$result = mysqli_query($conn, $fetchall);
while($row = mysqli_fetch_array($result)){
$id2 = $row['id'];
$no_1 = $row['number'];
$status_1 = $row['status'];
<td style="font-size: 10pt; width:7px;background-color:#4C724A; opacity:0.7; color:white">
<a style="background-color:#5a85dd; color:white; padding:10px; border-radius:10px; margin-top:20px; " data-toggle="modal" data-target="#popUpIA<?php echo $row['id'] ?>"></a></td>}<?php}?>

and this is my modal code.

<div class="modal fade"  id="popUpIA<?php echo $id2 ?>" tabindex="-1" role="dialog" aria-labelledby="popUpIATitle" aria-hidden="true">
                      <div class="modal-dialog modal-lg"  style="background-color: #4C724A; width:50%" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h5 class="modal-title" id="popUpIATitle"></h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                          <!-- <table style="width:100%"> -->

the problem is, modal can only popup when i clicked the last record and only can get the last id

5
  • Looks like you are not even creating the modal inside the loop.
    – CBroe
    Commented Oct 11, 2022 at 9:55
  • @CBroe I've tried modal inside the loop but the modal show in the bottom page instead of being popup. I read another source, it suggest to write modal outside the loop
    – user1004
    Commented Oct 11, 2022 at 9:58
  • 1
    "it suggest to write modal outside the loop" - then how would you expect to get an individual modal for each record? Then you would need to use JavaScript on the client side, to read the data from the triggering element, and dynamically populate your modal with that, at the moment it gets shown.
    – CBroe
    Commented Oct 11, 2022 at 10:00
  • Just in case you want to take the dynamic route, Bootstrap has an example on varying modal content including JS to fill the modal
    – brombeer
    Commented Oct 11, 2022 at 10:18
  • @CBroe thank you for the enlightenment. So I should add javascript. Ok I'll try. Thanks again
    – user1004
    Commented Oct 11, 2022 at 10:21

0

Browse other questions tagged or ask your own question.