0

I have created a table to fetch and display data from the table. I want to add a delete button to each row on the table so that when clicked on the delete button the entire row is deleted from the HTML table as well as the database. Tried several ways but didn't work out.

    <div class="container mt-3 ml-3">
<table class="table">
    <thead>
    <tr>
        <th>S.No</th>
        <th>Name</th>
        <th>Email</th>
        <th>Rating</th>
        <th>Review</th>
        <th>Image</th>
        <th>Suggestion</th>
        <th>NPS</th>
        <th>Delete</th>
    </tr>
    </thead>
    <tbody class="table-warning">

<?php
include 'database_conn.php';      // makes db connection

$sql = "SELECT feedbackID, name, email, rating, review, image, suggestion, nps
        FROM feedback 
        ORDER BY feedbackID Desc";
$queryResult = $dbConn->query($sql);

// Check for and handle query failure
if($queryResult === false) {
    echo "<p>Query failed: ".$dbConn->error."</p>\n";
    exit;
}
// Otherwise fetch all the rows returned by the query one by one
else {
    if ($queryResult->num_rows > 0) {
        while ($rowObj = $queryResult->fetch_object()) {
            echo "<tr>
                  <td>{$rowObj->feedbackID}</td>
                  <td>{$rowObj->name}</td>
                  <td>{$rowObj->email}</td>
                  <td>{$rowObj->rating}</td>
                  <td>{$rowObj->review}</td>
                  <td>{$rowObj->image}</td>
                  <td>{$rowObj->suggestion}</td>
                  <td>{$rowObj->nps}</td>
                  

              ";
        }

    }
}
?>

</tr>
    </tbody>
</table>
</div>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Gokul
  • 11
  • 4

0 Answers0