類(lèi)別的刪除功能
先給刪除標(biāo)簽和全部刪除標(biāo)簽都添加一個(gè)a標(biāo)簽
<?php <a href="typesave.php?action=del&id=<?php echo $row['id']?>">刪除</a> <a href="javascript:delall()">全部刪除</a><a href="typeadd.php"> 添加類(lèi)別</a>
用于獲取get請(qǐng)求,然后在typasave.php頁(yè)面進(jìn)行處理即可
在typesave.php頁(yè)面添加以下代碼:
elseif ($_GET["action"]=="del"){ $id=$_GET['id']; $sql = "delete from type where id=$id"; if ($mysqli->query($sql)) { echo "<script>alert('類(lèi)別刪除成功')</script>"; echo "<script>window.location='typelist.php'</script>"; } }elseif ($_GET["action"]=="delall"){ $arrid=$_GET["arrid"]; $arr=rtrim($arrid,","); $sql="delete from type where id in ($arr)"; $result=$mysqli->query($sql); if($result){ echo "<script>alert('類(lèi)別刪除成功!')</script>"; echo "<script>window.location.href='typelist.php'</script>"; }
效果展示: