a.php
<input type="checkbox" name="id[]" value=“1”>
<input type="checkbox" name="id[]" value=“2”>
..............b.phpfor($i=0;$i<count($id);$i++) {
$wc.= "\"".$id."\",";
}
$wc = "(".$id."'0')" ;
$strsql="delete from ***** where id in $wc ";
<input type="checkbox" name="id[]" value=“1”>
<input type="checkbox" name="id[]" value=“2”>
..............b.phpfor($i=0;$i<count($id);$i++) {
$wc.= "\"".$id."\",";
}
$wc = "(".$id."'0')" ;
$strsql="delete from ***** where id in $wc ";
<input type="checkbox" name="id[]" value=“1”>
(b.php):
for ($i=0;$i<count($id);$i++)
{
$tmpvalue=$id[$i];
if ($i==0) $tmpstring.=$tmpvalue;
else $tmpstring.=",".$tmpvalue;
}
$strsql="delete from ***** where id in ($tmpstring);
checkbox的名字用数组形式表示,这是php要求的
2、提交后$_POST中有一个id数组,保存有被选中checkbox的value
可以用连接起来使用
$id = $_POST["id"];
$strsql="delete from ***** where id in (". join(",",$id) .")";
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<?
if($check)
{
for($i=1;$i<=$countselected;$i++)
{
echo $checkboxid[$i]."<br>";
}
}
?>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
<?
for($i=1;$i<=5;$i++)
{
?>
<tr>
<td>
<input type="checkbox" name="checkboxid[<?echo $i?>]" value="选择[<?echo $i?>]">
选择<?echo $i?>
</td>
</tr>
<?
}
?>
<input type="hidden" name="countselected" value="<?echo $i?>">
<tr>
<td>
<input type="submit" name="check" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
举一反三