I have MySQL data that I am rendering in an HTML table using PHP. This is the full code of my table and PHP. It does output fine and looks how I would expect but I am wondering if there is a better way to write this code. Also, the 'Delete' button specifically, is there a better way to output the button itself as right now, I noticed especially on a mobile device, I will see a text cursor indicator when tapping the button as if I am trying to select the text on the button itself.
<div class="container" style="width: 95%;">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="col-sm-6">
Description
</th>
<th class="col-sm-2">
Date Created
</th>
<th class="col-sm-1">
Created By
</th>
<th class="col-sm-2" style="text-align: right;">
Edit - Delete
</th>
</tr>
<?php
$noLists = "<div>You have no lists. Why dont you create one?</div>";
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
$sql = "SELECT DISTINCT lists.id, lists.listdescription, lists.createdon, lists.createdby, lists.sharedlist FROM lists INNER JOIN users ON users.fname = '$displayname' AND users.fname = lists.createdby";
$result = $db->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$listID = $row["id"];
$listDescription = $row["listdescription"];
$createdOn = $row["createdon"];
$createdBy = $row["createdby"];
echo "<form>";
echo "<tr>";
echo "<td>$listDescription</td>";
echo "<td>$createdOn</td>";
echo "<td>$createdBy</td>";
echo "<td align=\"right\">";
echo "<form action='account.php' method='post'>";
echo "<input class=\"btn btn-success\" type=\"submit\" name=\"\" value=\"Edit\">";
echo "<a href='includes/deletelist.php?id=$row[id]'><input class=\"btn btn-danger\" value=Delete style=\"width: 85px;\"></a>
<!--<a href=\"index.php?id=$id\">Delete</a>-->
</td>";
}
} else {
echo "</thead>";
echo "<tbody>";
echo "</tbody>";
echo "</table>";
echo "<h4> $noLists</h4>";
}
$db->close();
?>