Php table only being able to open 1 modal

Currently I am working on adding an edit button into my page that is hooked up to a table. When you click the edit button it is supposed to open a modal. After finishing a bunch of work and trying the same system on a different page I noticed it only works with the first row in the mysql database, the rest of the data doesn’t want to open the modal. I tried both defining the data and leaving it as row data and both are still giving the issue.

There is a bunch of lines so I’m just gonna give the important stuff unless someone needs the other information.

$query = “SELECT * FROM users WHERE blacklisted < ‘1’ ORDER BY id DESC”;
$res = $connect->query($query);
if($res->num_rows > 0):
while($row = $res->fetch_assoc()){
$userid = $row[‘id’];
?>
<td> <a href="#edituser<?php echo $userid; ?>" data-toggle="modal"><button class='btn btn-primary' type='button'>Edit</button></a> </td>

This is the main information for the modal

<div class="modal fade" id="edituser<?php echo $userid; ?>">

I know I kept it to the bare minimum but my code has a very large number of lines for example if statements in the modal that are unnecesary since they technically work

This looks like you’re rendering a separate modal for each user; so you have something like;

<td><a href="#edituser1" data-toggle="modal">...</a></td>
<td><a href="#edituser2" data-toggle="modal">...</a></td>
<td><a href="#edituser3" data-toggle="modal">...</a></td>

...

<div class="modal fade" id="edituser1">...</div>
<div class="modal fade" id="edituser2">...</div>
<div class="modal fade" id="edituser3">...</div>

in your rendered page. Is that right?

Sponsor our Newsletter | Privacy Policy | Terms of Service