比如说有一个数据表,名字是test,里面有两列,分别是id和name,我想要把表的内容取出来,显示成一个表格,同时在每行记录的前面有一个checkbox,通过checkbox选定记录并删除,请问这个程序应该怎么写啊。
谢谢大家

解决方案 »

  1.   

    <form method="post" action="你的页面">
    <input type="checkbox" name="id" value="1" checked>
    <input type="checkbox" name="id" value="2" checked>
    <input type="checkbox" name="id" value="3">
    <input type="submit">
    </form>当你提交的时候$_POST['id']看看
      

  2.   

    谢谢您 那从checkbox取值该怎么写?
      

  3.   

    $_POST['id'] 就是checkbox的值。 你把他们的value设为你每行的id不就行了。
      

  4.   

    echo '<td><input type="checkbox" name="id[]" value=<?php echo $data; ?>></td>';复选框用的这句话,
    这是一个循环里面的语句,共循环五次,$data的值从1到5,
    表单提交的页面用如下两句话
    $array=$_post['id']; 
    print_r($array);
    没有输出,请大家帮帮忙
      

  5.   


       foreach($_POST[id] as $v){
           mysql_query("delete from t_name where id=".$v);
           echo "删除成功";
       }
      

  6.   

    谢谢您,还是不行啊,我把代码贴出来请您帮忙看看
    表单页面:<html>
    <head>
    </head>

    <?php
    $link=mysql_connect("localhost","root","123456");
    mysql_select_db('check');
    mysql_query("SET NAMES UTF8");
    $result=mysql_query("select * from tset");
    //print_r($result);
    echo '<table align="echter"width="80%"border="1">';
    echo '<form name="test" action="sc.php" method="post">';
    echo '<th>check</th><th>id</th>';
    while($row=mysql_fetch_row($result))
    {
    echo '<tr>';
    foreach($row as $data)
    {
    echo $data;
    echo '<td><input type="checkbox" name="id[]" value=<?php echo $data; ?>></td>';
    echo '<td>'.$data.'</td>';
    }
    echo '</tr>';
    }

    echo '</table>';
    mysql_free_result($result);
    mysql_close($link);
    echo '<center><input type=submit value="删除"></center>';
    echo '</form>';
    ?>
    <body>
    </body>
    </html>
    $data=[0,1,2,3,4]
    表单提交的页面
    <?php $link=mysql_connect("localhost","root","123456"); 
    mysql_select_db("check");
     
    $array=$_post['id']; 
    print_r($array);
    foreach($_POST[id] as $v){ 
    $flag=mysql_query("delete from tset where id=".$v);
    if($flag)
    {
    echo "ok";
    }

    mysql_close(); 
    ?>
    好像是传值不成功
    请您帮忙看看 谢谢
      

  7.   

    http://www.111cn.net/phper/18/3adfd40e7627b9ba10cd61e1c1c42bb8.htm
    http://www.111cn.net/phper/php-database/36763.htm
    也可以到gg搜索啊
      

  8.   

    $array=$_POST['id'];   //大写。
    print_r($arrat); 有值吗。  另外你id[]赋值可能有问题。 把id赋值。 while($row=mysql_fetch_assoc($result))
            {
                echo '<tr>';
                foreach($row as $data)
                {
                  //  echo $data;
                   // echo '<td><input type="checkbox" name="id[]" value=<?php echo $data; ?>></td>';
                    echo '<td>'.$data.'</td>';
                }
                echo '<td><input type="checkbox" name="id[]" value="'.$row[id].'" /></td>';
                echo '</tr>';
            }这样试试。
      

  9.   

    print_r($arrat); 没有值啊,输出就是Array ( [0] => ) 
      

  10.   

    好像也没有 Array ( [id] => Array ( [0] => ) ) 
      

  11.   

    你要选中checkbox提交后才有值啊
      

  12.   


    <html>
        <head>
        </head>
        
        <?php
            $link=mysql_connect("localhost","root","123456");
            mysql_select_db('check');
            mysql_query("SET NAMES UTF8");
            $result=mysql_query("select * from tset");
            //print_r($result);
            echo '<table align="echter"width="80%"border="1">';
            echo '<form name="test" action="sc.php" method="post">';
            echo '<th>check</th><th>id</th>';
            while($row=mysql_fetch_row($result))
            {
                echo '<tr>';
                foreach($row as $data)
                {
                    echo $data;
                    echo "<td><input type='checkbox' name='id[]' value=$data></td>";//问题出在这一句,已经帮你修改了!
                    echo '<td>'.$data.'</td>';
                }
                echo '</tr>';
            }
            
            echo '</table>';
            mysql_free_result($result);
            mysql_close($link);
            echo '<center><input type=submit value="删除"></center>';
            echo '</form>';
        ?>
        <body>
        </body>
    </html>测试通过了!
      

  13.   


    你没有删除的原因在于
    while($row = mysql_fetch_row($result))
    mysql-fetch_row返回的是数字索引数组,而不是关联数组
    所以你需要用用
    mysql_fetch_array()或者mysql_fetch_assoc()
    然后用jordan的方式删除。