删除多条记录的问题
删除多条记录的问题
用户管理页面,删除单条的记录我现在已经掌握了,可是如何一次删除多条记录呢?
我知道用循环,但是具体如何取得选中的那些记录的id呢?
哪位大哥帮我写下完整的代码吧。。。
我的代码:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><SCRIPT language=javascript>
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.name != 'chkall')
e.checked = form.chkall.checked;
}
}
</SCRIPT>
<body>
<form name=myform method='post' action='' onsubmit='return checkdata();'>
<table width="502" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr>
<td colspan="5" align="center" valign="middle" bgcolor="#666666"><span class="STYLE2">用户管理</span></td>
</tr>
<tr>
<td width="37" align="center" bgcolor="#FFFFFF"><input type="checkbox" name="chkall" onClick="javascript:CheckAll(this.form)"></td>
<td width="145" align="center" bgcolor="#FFFFFF"><strong>用户名</strong></td>
<td width="94" align="center" bgcolor="#FFFFFF"><strong>状态</strong></td>
<td width="95" align="center" bgcolor="#FFFFFF"><strong>编辑</strong></td>
<td width="95" align="center" bgcolor="#FFFFFF"><strong>删除</strong></td>
</tr>
<?php
while($Row=mysql_fetch_array($result))
{
$wyx_id=$Row["wyx_id"];
$wyx_name=$Row["wyx_name"];
$wyx_pass=$Row["wyx_pass"];
?>
<tr>
<td width="37" align="center" bgcolor="#FFFFFF"><input type="checkbox" value=""></td>
<td width="145" align="center" bgcolor="#FFFFFF"><?php echo $wyx_name ?></td>
<td width="94" align="center" bgcolor="#FFFFFF"></td>
<td width="95" align="center" bgcolor="#FFFFFF"><a href="admin_useredit.php?id=<?php echo $wyx_id ?>">编辑</a></td>
<td width="95" align="center" bgcolor="#FFFFFF"><a href="admin_userdel.php?id=<?php echo $wyx_id ?>">删除</a></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" bgcolor="#FFFFFF">
<input type=submit name=submit value=删除>
</td>
</tr>
</table>
</form>
</body>
$wyx_id=$_POST['wyx_id'];
foreach($wyx_id as $value)
{
$sql="delete from table where id=$value";
}
这样就OK了
<br><font color="#e78608">------解决方案--------------------</font><br><input type="checkbox" name="ids[]" value="这里要输入id"><br>post 过去就是<br>$ids[0]=id1;<br>$ids[1]=id2; 这个形式,楼上的已经说的很明白了.
<br><font color="#e78608">------解决方案--------------------</font><br>多条主要用条件语句来控制。<br><br>比如说id in ...,或者id > ... 又或者 id not in ...<br><br>等等。
<br><font color="#e78608">------解决方案-------------------- <div class="clear"></div></font>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号