您的位置:程序门 -> web 开发 -> php



我在做php中的批量删除时,出现了问题?请高手帮忙


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


我在做php中的批量删除时,出现了问题?请高手帮忙
发表于:2007-05-30 23:07:41 楼主
我用的是复选框,但是我提交过来的时候总是只得到一个值,请大家帮帮忙啊
发表于:2007-05-30 23:21:351楼 得分:0
复选框名字用数组来表示:

<input   type= "checkbox "   name= "checkbox[] "   value= " ">
服务器端取得值为数组,就可以处理了.
发表于:2007-05-30 23:50:352楼 得分:0
哦   !那怎么实现全选和反选啊??
发表于:2007-05-31 00:16:193楼 得分:0
<!doctype   html   public   "-//w3c//dtd   html   4.01   transitional//en "   "http://www.w3.org/tr/html4/loose.dtd ">
<html>
<head>
<meta   http-equiv= "content-type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<script   language= "javascript ">  
function   selectall()  
{  
for(var   i=0;i <document.form1.del[].length;i++)  
{  
document.form1.del[][i].checked=false;  
}  
}  
function   unselect()  
{  
for(var   i=0;i <document.form1.del[].length;i++)  
{  
if(document.form1.del[][i].checked)  
{  
document.form1.del[][i].checked=false;  
}  
else  
{  
document.form1.del[][i].checked=true;  
}  
}  
}  
</script>  
<body>
<form   name= "form1 "   method= "post "   action= "delpost.php ">
    <table   width= "500 "   border= "0 "   align= "center "   cellpadding= "0 "   cellspacing= "1 "   bgcolor= "#000000 ">
        <tr   bgcolor= "#ffffff ">
            <td   width= "96 "   height= "25 "> <div   align= "center "> 用户名 </div> </td>
            <td   width= "136 "   height= "25 "> <div   align= "center "> 密码 </div> </td>
            <td   width= "115 "> <div   align= "center "> 登陆时间 </div> </td>
            <td   width= "148 "> <div   align= "center ">
                <input   name= "delete "   type= "submit "   id= "delete "   value= "删除 ">
                <input   type= "button "   name= "submit "   value= "全选 "   onclick= "selectall(); ">
                <input   type= "button "   name= "submit2 "   value= "反选 "   onclick= "unselect(); ">
            </div> </td>
        </tr>
        <?php
    require_once( "mysql.php ");
    $sql= "select   *   from   admin ";
    $result=dbconn($sql);
    while   ($array=mysql_fetch_array($result[ "rs "])){
    ?>
        <tr   bgcolor= "#ffffff ">
            <td   height= "25 "> <div   align= "center ">
                    <?=$array[ "a_zhanghao "]?>
            </div> </td>
            <td   height= "25 "> <div   align= "center ">
                    <?=$array[ "a_mima "]?>
            </div> </td>
            <td> <div   align= "center ">
                    <?=$array[ "login_time "]?>
            </div> </td>
            <td> <div   align= "center ">
                <input   name= "del[] "   type= "checkbox "   id= "del[] "   value= " <?php   echo   $array[ "a_id "]?> ">
</div> </td>
        </tr>
        <?php
}
?>
    </table>
</form>
</body>
</html>
调用的地方缺少对象,是怎么会事啊?
发表于:2007-05-31 08:05:474楼 得分:0
没有人知道吗?
发表于:2007-05-31 08:11:155楼 得分:0
<form   action= "? "   method= "post ">
<input   type= "checkbox "   name= "checkbox[1] "   value= "a ">
<input   type= "checkbox "   name= "checkbox[2] "   value= "b ">
<input   type= "checkbox "   name= "checkbox[3] "   value= "c ">
<input   type= "submit ">
</form>
程序
<?
if(!empty($_post[ 'checkbox ']))
foreach($_post[ 'checkbox ']   as   $k=> $v){
    echo   $k. '= '.$v. ' <br> ';
}
?>
发表于:2007-05-31 08:15:116楼 得分:0
我说的是全选和反选啊!我上面的代码怎么改才是正确的啊??
发表于:2007-05-31 09:04:357楼 得分:0
帮帮忙撒!大家
发表于:2007-05-31 09:25:578楼 得分:0
写法不对,请使用getelementsbyname
将javascript改成以下试试
===============================
<script   language= "javascript ">

var   sid   =   document.getelementsbyname( 'del[] ');

function   selectall()
{

for(var   i=0;i <sid.length;i++)
{
sid[i].checked=true;
}
}
function   unselect()
{
for(var   i=0;i <sid.length;i++)
{
if(sid[i].checked)
{
sid[i].checked=false;
}
else
{
sid[i].checked=true;
}
}
}
</script>
发表于:2007-05-31 09:31:169楼 得分:0
看来不懂起码的javascript呀。。。。


快速检索

最新资讯
热门点击