《PHP學(xué)習(xí):php批量刪除操作(數(shù)據(jù)訪問(wèn))》要點(diǎn):
本文介紹了PHP學(xué)習(xí):php批量刪除操作(數(shù)據(jù)訪問(wèn)),希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
本文實(shí)例為大家分享了php批量刪除操作的具體代碼,供大家參考,具體內(nèi)容如下PHP教程
PHP教程
1.批量刪除頁(yè)面 piliangcaozuo.phpPHP教程
<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>名稱(chēng)</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>
引用的封裝類(lèi) DBDA.class1.phpPHP教程
<?php class DBDA { public $host = "localhost"; public $uid = "root"; public $pwd = "123"; public $dbname = "test_123"; //執(zhí)行SQL語(yǔ)句返回相應(yīng)的結(jié)果 //$sql 要執(zhí)行的SQL語(yǔ)句 //$type 代表SQL語(yǔ)句的類(lèi)型,0代表增刪改,1代表查詢(xún) function query($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $result = $db->query($sql); if($type) { //如果是查詢(xún),顯示數(shù)據(jù) return $result->fetch_all(); } else { //如果是增刪改,返回true或者false return $result; } } }
2.刪除處理界面 sanchu.phpPHP教程
<?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í)有所幫助,也希望大家多多支持維易PHP.PHP教程
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/744.html