本文實(shí)例為大家分享了php批量刪除操作的具體代碼,供大家參考,具體內(nèi)容如下
1.批量刪除頁面 piliangcaozuo.php
<body> <form action="shanchu.php" method="post"> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td><input type="checkbox" name="qx" onclick="quanxuan(this)"/>代號(hào)</td> <td>名稱</td> </tr> <?php require"DBDA.class1.php"; $db = new DBDA(); $sql = "select * from nation"; $arr = $db->query($sql); foreach($arr as $v) { echo "<tr> <td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}'/>{$v[0]}</td> <td>{$v[1]}</td> </tr>"; } ?> </table> <input type="submit" value="批量刪除" /> </form> </body> <script type="text/javascript"> function quanxuan(qx) { var ck=document.getElementsByClassName("ck"); if(qx.checked) { for(var 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> </html>
引用的封裝類 DBDA.class1.php
<?php class DBDA { public $host = "localhost"; public $uid = "root"; public $pwd = "123"; public $dbname = "test_123"; //執(zhí)行SQL語句返回相應(yīng)的結(jié)果 //$sql 要執(zhí)行的SQL語句 //$type 代表SQL語句的類型,0代表增刪改,1代表查詢 function query($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $result = $db->query($sql); if($type) { //如果是查詢,顯示數(shù)據(jù) return $result->fetch_all(); } else { //如果是增刪改,返回true或者false return $result; } } }
2.刪除處理界面 sanchu.php
<?php $arr = $_POST["ck"]; require"DBDA.class.php"; $db = new DBDA(); //delete from nation where code in('n001','n002','n003') $str = implode("','",$arr); $sql = "delete from nation where code in('{$str}')"; /*echo $sql;*/ if($db->query($sql,0)) { header("location:piliangcaozuo.php"); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。