Nyd
Nyd

Reputation: 107

How to add delete button in a bootstrap table

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>";

Upvotes: 0

Views: 6166

Answers (2)

c4pone
c4pone

Reputation: 797

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 ?>

Upvotes: 1

Realit&#228;tsverlust
Realit&#228;tsverlust

Reputation: 3953

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.

Upvotes: 0

Related Questions