当前位置:编程学习 > php >>

[求助]PHP复选框获值的问题 十万火急!!!!!

补充:我的毕设,马上要答辩了,急啊,跪求各位高手解答,感激不尽!!! 是一个论坛,需要在后台对帖子进行管理,利用复选框选中需要的帖子,然后点击下方的按钮设置精华帖,代码要怎么写呢? 下面是部分代码,但是有问题,反正实现不了!!! 复选框的代码:<input name="tb_send_id[]" type="checkbox" value="<?php echo $myrow[tb_send_id];?>"> 精华帖按钮的代码:<input type="submit" name="Submit" value="精华帖"> 设置精华帖成功的代码: <?php session_start(); include("conn/conn.php"); if($Submit=="精华帖"){ while(list($name,$value)=each($_POST)){ $result=mysql_query("update tb_forum_send set tb_send_type_distillate='1' where tb_send_id='".$name."'"); if($result==true){ echo "<script>alert('精华帖激活成功!'); window.location.href='index.php?title=帖子管理';</script>";}} } .......
答案:unset($_POST[Submit]);
 while(list($name,$value)=each($_POST)){    
         $result=mysql_query("update tb_forum_send set tb_send_type_distillate='1' where tb_send_id='".$value."'");          
试试
其他:
<input type="checkbox" name="del[<?php echo $l_result['id']; ?>]" value="<?php echo $l_result['id']; ?>"> 

上面这个有两点需要注意,第一点,需要把这个修改成这样:
<input type="checkbox" name="del[]" value="<?php echo $l_result['id']; ?>"> 
第二点:$_POST[del]取到的是一个数组,你要通过数组的方式去取值。 你干嘛一些要用list呢?我不是很熟,但是这样写肯定可以实现。    
  $c=  $_POST['tb_send_id'];  // 获取前台点击过的所有cbox的值
foreach( $c   as  $v)   //循环的进行修改
{
$result=mysql_query("update tb_forum_send set tb_send_type_distillate='1' where      tb_send_id='$v");   //既然已经使用双引号 就可以不用 连接符了  
}

后面的代码略。。。没有不行的道理

你还要检查其他,数据库连接有没有的问题 代码如下就可以了

<?php 
session_start(); include("conn/conn.php");
if($Submit=="精华帖"){
    $ids = isset($_POST['tb_send_id'])&&is_array($_POST['tb_send_id'])?join(",",$_POST['tb_send_id']):0;
         $result=mysql_query("update tb_forum_send set tb_send_type_distillate='1' where tb_send_id in($ids)");          
    if($result==true){
        echo "<script>alert('精华帖激活成功!'); window.location.href='index.php?title=帖子管理';</script>";}
}

你原来的之所以不行,是因为 while(list($name,$value)=each($_POST)){ 这句不对,还有你把转向放到循环中了,如果能处理的话,则只处理了一次就转向了, 

上一个:PHP 源代码!
下一个:phpweb开源程序怎么样?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,