I am trying to access the data of perticular row of the table from the database by modal window.The first for loop is used for the row of the data of the webpage and the second for loop for the column.I am trying to show the every column of the particular row by the the modal window which is to shown by clicking the view button.But it is shown the same data in the modal window for every view button.How can I fix the code? please help me.
<?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">×</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>
In your example every modal has the same id myModal
. Maybe that's the cause. Try making it unique:
data-target="#myModal-<?php echo $row["Student_ID"] ?>"
<div id="myModal-<?php echo $row["Student_ID"] ?>"