PHP 大量操作刪除,支援單個刪除

來源:互聯網
上載者:User

標籤:

PHP  執行部分:

 1 <?php 2 include(‘checkadmin.php‘); 3 header(‘Content-Type: text/html; charset=utf-8‘); 4 if($_POST[‘btnSave‘]){ 5      6     if(empty($_POST[‘id‘])){ 7             echo"<script>alert(‘必須選擇一個產品,才可以刪除!‘);history.back(-1);</script>"; 8             exit; 9         }else{10         /*如果要擷取全部數值則使用下面代碼*/11         12         $id= implode(",",$_POST[‘id‘]);13         $str="DELETE FROM `product` where id in ($id)";14         mysql_query($str);15         echo "<script>alert(‘刪除成功!‘);window.location.href=‘product_list.php‘;</script>";16     }17 }18 ?>

HTML 頁面部分:

<form id="form2" name="form2" method="post" action="del_product.php">    <label>        <input type="checkbox" name="id[]" value="1" style="background:none; border:none;" />            1    </label>    <label>        <input type="checkbox" name="id[]" value="2" style="background:none; border:none;" />            2    </label>    <label>        <input type="checkbox" name="id[]" value="3" style="background:none; border:none;" />            3    </label>    <label>        <input type="checkbox" name="id[]" value="4" style="background:none; border:none;" />            4    </label>    <label>        <input type="checkbox" name="id[]" value="5" style="background:none; border:none;" />            5    </label>    <div style="padding-left:20px;">        <input type="button" value="全選" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox(‘all‘)"/>        <input type="button" value="反選" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox(‘reverse‘)"/>        <input type="submit" name="btnSave" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" value="刪除"/>    </div></form>

JS判斷部分:


<script type="text/javascript" language="javascript"> function selectBox(selectType){ var checkboxis = document.getElementsByName("id[]"); if(selectType == "reverse"){ for (var i=0; i<checkboxis.length; i++){ //alert(checkboxis[i].checked); checkboxis[i].checked = !checkboxis[i].checked; } } else if(selectType == "all") { for (var i=0; i<checkboxis.length; i++){ //alert(checkboxis[i].checked); checkboxis[i].checked = true; } }}</script>

 

PHP 大量操作刪除,支援單個刪除

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.