php大量刪除操作

來源:互聯網
上載者:User
大量刪除多條記錄,對於比較多的資訊,如果沒有大量刪除功能是非常麻煩的。

1.從資料庫中拿一張表過來,寫個複選框進行選擇

可以加全選複選框

串連資料庫什麼的都不寫啦

代碼:

<form action="piliangshanchu.php" method="post" ><table border="1" cellspacing="0" cellpadding="0">  <tr>    <td width="200">      <input type="checkbox" value="''" name="dx" onclick="checkall(this)" />      編號</td>    <td width="200">姓名</td>    <td width="200">電話</td>    <td width="200" >分組</td>    <td width="200" >操作</td>  </tr><tr>    <td>    <input type='checkbox' value='{$attr[0]}' name='item[]' class='ck' />    {$attr[0]}</td>     <td>{$str}</td>    <td>{$attr[2]}</td>    <td>{$nation}</td></tr></table>  <input type="submit" value="大量刪除"/>  </form>

外加一個大量刪除按鈕

:

我如果點擊全選,利用js點擊事件就可以輕鬆實現全選

代碼:

<script>  function xxx(qx)  {//全選多選的選中狀態    var ck = document.getElementsByClassName("ck"); //讓下面所有的多選選中狀態改變    if(qx.checked)    {      for(i = 0;i < ck.length ; i++)      {        ck[i].setAttribute("checked","checked");//狀態改變為選中      }    }    else    {      for(var i = 0;i < ck.length;i++)      {        ck[i].removeAttribute("checked");//移除選中      }    }  }</script>

2.刪除的處理頁面

代碼:

<?php$arr = $_POST["item"];$db = new mysqli("localhost","root","12345678","heiheihei");//foreach($arr as $v)//{//  $sql = "delete from contacts WHERE id='{$v}'";//  $db->query($sql);//}$str = implode("','",$arr);//拼接字元,$sql = "delete from contacts WHERE id in('{$str}')";//2','8','4if($db->query($sql))//判斷是否查詢成功,{  header("location:shouye.php");  //成功就跳轉}?>

用foreach資料轉送過慢,刪除遍曆繁多,因此直接判斷;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.