I am creating a database and I am trying to make a button that shows the users ticket information. Whenever I click the button I want it to say the individual persons name, but no matter which user I click on it only shows the first users name and not the name of the person who's button I clicked on. Here is the code for the modal button
$count = mysqli_num_rows($query);
if($count ==0){
$output = 'There was no search result!';
}else{
$counter=0;
while($row = mysqli_fetch_array($query)){
$fname = $row['f_name'];
$lname = $row['l_name'];
$email = $row['email'];
$password = $row['password'];
$userID = $row['userID'];
$status = $row['status'];
if($status == 'Active'){
$classStatus='label-success';
}else{
$classStatus='label-danger';
}
$output.='<tr>
<td>
<a class="tv8" href="#"><img src="images/tv8.png" alt="Send TeamView 8 Link to Email" style="width:30px;height:30px;"></a>
<img src="images/cert.png" alt="Send Certification to Email" style="width:30px;height:30px;">
</td>
<td>' . $fname . ' ' . $lname . '</td>
<td id='.++$counter.'>' . $email. '</td>
<td>' . $userID . '</td>
<td>' . $password . '</td>
<td><h4><span class="label ' .$classStatus.'">'.$status.'</span></h4></td>
<td><button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#myModal">View</button></td><!-- Trigger the modal with a button -->
<!-- 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">Ticket Information</h4>
</div>
<div class="modal-body">
<p>' . $fname . ' ' . $lname . ' ticket info will be found here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
How can I make this code show different peoples names when I click the button instead of just the first person listed in the database?
Use that $counter variable you've set to distinguish between the Mymodal ids. Change your button to this:
<button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#myModal' . $counter . '">
and your modal:
<div id="myModal' . $counter . '" class="modal fade" role="dialog">
I wouldn't do it like this myself but this should solve your problem