如何在数据库中通过引导创建动态模式窗口?

时间:2018-10-18 18:08:27

标签: php mysql database

我试图通过模态窗口从数据库访问表的特定行的数据。第一个for循环用于网页数据的行,第二个for循环用于列的行。通过单击视图按钮显示的模式窗口显示特定行的每一列。但是在模式窗口中每个视图按钮都显示相同的数据。如何修复代码?请帮助我。

    <?php


$db = mysqli_connect('localhost', 'root','', 'studentmanagementsystem');
$query = mysqli_query($db, "select * from student");
$rowcount = mysqli_num_rows($query);

?>

<table border = "0" align= "center">

<?php
    for($j = 1; $j <= $rowcount/5; $j++){

?>

<tr>

<?php
    for($i = 1; $i <= 5; $i++){
        $row = mysqli_fetch_array($query);

?>


        <td><img src="images/<?php echo $row["photo"]?>" height="150px" width="150px" style="border-radius:60px;"</td>
        <td><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">View</button></td>




        <!-- Modal -->
                <div id="myModal" class="modal fade" role="dialog">
                  <div class="modal-dialog">

                    <!-- Modal content-->
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Student Details</h4>
                      </div>
                      <div class="modal-body">
                        <p><img src="images/<?php echo $row["photo"]?>" height="150px" width="150px"</p>
                        <p>Name: <?php echo $row["First_Name"];echo " "; echo $row["Last_Name"]?></p>
                        <p>ID: <?php echo $row["Student_ID"] ?></p>
                        <p>Address: <?php echo $row["Address"] ?></p>
                        <p>Email: <?php echo $row["Email"] ?></p>
                        <p>Contact: <?php echo $row["Contact_NO"] ?></p>
                        <p>Birth Date: <?php echo $row["Date_of_birth"] ?></p>

                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      </div>
                    </div>

                  </div>
                </div>



<?php
    }
?>

<?php
    }
?>
    </tr>





</table>

1 个答案:

答案 0 :(得分:0)

在您的示例中,每个模态都具有相同的ID myModal。也许这就是原因。尝试使其独特:

data-target="#myModal-<?php echo $row["Student_ID"] ?>"

<div id="myModal-<?php echo $row["Student_ID"] ?>"