操作時點擊刪除連接時就會會獲取到當前條目的id然後程序獲取到當前id進行刪除操作。
<?php教程
include("conn.php");
$query = "select * from new order by id desc";
$res = mysql教程_query($query);
while($rows =mysql_fetch_array($res)){ //將查詢到結果拆到$rows數組中
?>
<table>
<tr>
<td>標題:<?php echo$rows['title']?></td><td><a href="del.php?<?php $tid = $rows['id'] ?>">[刪除]</a></td><td><a href="">[修改]</a></td>
</tr>
<table>
<?php
}
?>
<form action="addnews.php" method="post">
作者:<input type="text" name="author"/><br/><br/>
標題:<input type="text" name="title" size="20"><br/><br/>
內容:<textarea name="content" cols="20" rows="20"></textarea>
<input type="submit" value="提交" name="submit"/>
</form>
del.php代碼
<?php
$del = "delect from test where id in ($tid)";
$res = mysql_query($del);
if($res){
echo "刪除成功";
}else{
echo "刪除失敗";
}
?>