dongyinju5977 2014-01-06 10:30
浏览 11
已采纳

从表中删除多个条目[关闭]

showall.php first fetch all the values from database and arrayToHtmlTable function make them into table , I have added individual delete and update button for each rows but I want to add checkbox box to delete multiple enteries but not able to figure out how to complete it

include "arrayToTable.php";
$bd=new sbs();
$sd=new arrayToTable();
$insert=false;
$bd->setDB(luDigi_db::factory());
if(isset($_GET['info'])) {
    if($_GET['info']=="coupon") {
            $r=$bd->execute("create_coupon","*","");
            $page="coupon";
    if(count($r)==0){
            echo "there is no data ";
    } else {
            echo '<input type="submit" name="delete"  value="delete" >';
            print_r($sd->arrayToHtmlTable($r,$page));
            }
    }





 function arrayToHtmlTable($arr,$page) {
       if ($arr > 0) {
        foreach($arr[0] as $t=>$v)
            $colnams[] = $t;
       }
        $r = '';
        $r .=' <table cellpadding="10" border="1" style="width:550px;"><tr>';
        for ($i=0; $i<count($colnams); $i++)  {
            $r .= "<td>$colnams[$i]</td>";
        }     
            $r .= '<td>DELETE</td>';
            $r .=   '<td>UPDATE</td>';
            $r .=   '</tr>';
        for ($i=0; $i<count($arr) ; $i++)  {
            $r .='<tr>';
        for ($ii=0; $ii < count($colnams); $ii++)  {
            $e= serialize($arr[$i][$colnams[$ii]]);
            $j=unserialize($e);
            $r .=   "<td>$j</td>";
        }
            $r .= '<td><form action="del.php" method="get">
            <input type="hidden" name="del" value="'.$arr[$i]['id'].'"> 
            <input type="hidden" name="page" value="'.$page.'"> 
            <input type="submit" value="DELETE" >
            </form></td>';
            $r .=   '<td><form action="update.php" method="get">
            <input type="hidden" name="upd" value="'.$arr[$i]['id'].'"> 
            <input type="hidden" name="page" value="'.$page.'"> 
            <input type="submit" value="UPDATE" >
            </form></td>';
        if($page=="coupon") {
            $r.= '<td><input type="checkbox" name="led[]" value="'.$arr[$i]['id'].'"></td>';
        }
            $r .="</tr>";
        }     
        $r .=   '</table>';
            return $r;
            }
  • 写回答

1条回答 默认 最新

  • dtbsezxw28056 2014-01-06 10:46
    关注

    Add these two checkboxes to each of your table rows

    <input type="checkbox" name="delete" value="'.$arr[$i]['id'].'">
    <input type="checkbox" name="update" value="'.$arr[$i]['id'].'">
    

    When the form is submitted, you will have two arrays $_POST['delete'] and $_POST['update'] which holdt the IDs to be deleted/update. Then all you have to do is iterate through these arrays to construct your DELETE and UPDATE queries. Or if you are using prepared statements, construct two queries and execute them for each ID.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来