请看一下循环:
$category = $mysqli->query('SELECT * FROM category');
$divcounter = 0;
while($row = $category->fetch_assoc()) {
print '<div class="item col-xs-12 col-sm-6 col-md-3 col-lg-2">';
print '<h4><a href="#tvb'.$row["id"].'" data-toggle="collapse" aria-expanded="false" aria-controls="tvb'.$row["id"].'" class="label label-success full-width"><span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span> '.$row["catname"].'</a></h4>';
print '<div id="tvb'.$row["id"].'">';
$link = $mysqli->query("SELECT * FROM links WHERE category='{$row["id"]}'");
while($row = $link->fetch_assoc()) {
print '<li><a href="'.$row["url"].'">'.$row["name"].'</a> <span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span></li>';
}
$link->free();
print '</div>';
print '</div>';
$divcounter++;
!($divcounter % 2) ? print '<div class="clearfix visible-sm-block"></div>' : '';
!($divcounter % 4) ? print '<div class="clearfix visible-md-block"></div>' : '';
!($divcounter % 6) ? print '<div class="clearfix visible-lg-block"></div>' : '';
}
请告知我如何创建一个位于li旁边的按钮来删除db中当前列出的行?感谢
<span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span>
这是delete.php的内容:
if(isset($_POST['catid']) and is_numeric($_POST['catid']))
$id=$_POST['catid'];
$query = "DELETE FROM category WHERE id=(?)";
$statement = $mysqli->prepare($query);
$statement->bind_param('i', $id);
$statement->execute();
$statement->close();
答案 0 :(得分:1)
while($row = $link->fetch_assoc()) {
print '<li><a href="delete.php?id=' . $row["id"] . '" onclick="alert(\'Are you sure you want to delete this record?\')">delete</a><a href="'.$row["url"].'">'.$row["name"].'</a> <span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span></li>';
}