本人在写聊天室程序时,需要把以前聊天记录显示出来,欲以删除。请看下列程序清单:
<?
.........
//从数据库中取出记录,且每条记录前都有一个复选框。
while($row = mysql_fetch_array($result))
{
$no=$row[no];
$chat_name=$row[snick];
$chat_con= $row[msg];
echo "
<tr>
<td width='38'>
<input type='checkbox' name='sub[$no]' value='checkbox'>
</td>
<td width='109'>$chat_name</td>
<td width='553'>$chat_con</td>
</tr>
";
}
........
?>
<?
//以下是实现删除功能。
<?
include "con_mysql.inc";
$query="select * from msg";
$result1 = mysql_query($query);
for ($i=0;$i<=$num;$i++)
{
if ($sub[$i] != "")
{
$query = "delete from msg where no='$sub[$i]'";
mysql_query($query);
// echo $query;
}
}
//echo "<script language=\"javascript\">history.back();alert(\"删除完毕!! \");</script>";
echo "<script language=\"javascript\">alert(\"删除完毕!!。\");window.location.href='/chat/bin/clear.php';</script>";
exit;
?>
|