How to add delete button in a bootstrap table

6.1k Views Asked by At

These are the codes that I used to achieve a legitimate table. However, I can't seem to add delete buttons in the column called "Delete". I could really use a little help here.

  <tr>
    <th>#</th>
    <th>Username</th>
    <th>Email Address</th>
    <th>Last Login</th>
    <th>Country</th>
    <th>Delete</th>
  </tr>

</thead>
<tbody>
  <?php
    if ($result2->num_rows > 0) {
      // output data of each row
       while ($rows = $result2->fetch_assoc()) {
         print "<tr> <td>";
         echo $rows['id'];
         print "</td> <td>";
         echo $rows['user_name'];
         print "</td> <td>";
         echo $rows['email_address'];
         print "</td> <td>";
         echo $rows['last_login'];
         print "</td> <td>";
         echo $rows['country'];
         print "</td> <td>";    
         print "</td> <td>";
2

There are 2 best solutions below

0
On BEST ANSWER

Something like that:

<?php if ($result2->num_rows > 0) :?>
    <?php while ($rows = $result2->fetch_assoc()) :?>
    <tr>
        <td><?php echo $rows['id']; ?></td>
        <td><?php echo $rows['user_name']; ?></td>
        <td><?php echo $rows['email_address']; ?></td>
        <td><?php echo $rows['last_login']; ?></td>
        <td><?php echo $rows['country']; ?></td>
        <td><button type="button" class="btn btn-danger">Danger</button></td>
    </tr>
    <?php endwhile ?>
<?php endif ?>
0
On

To add a simple delete button:

while ($rows = $result2->fetch_assoc()) {
    ...
    print "</td> <td>";
    print "<a href='delete.php'>Delete</href>
    print "</td> <td>";
    ...

Of course, you have to create the delete.php yourself which is doing the actual delete action. Also, this isn't a button yet. But you can use CSS to make it look like one.