Php batch Delete (Data Access) and php batch Delete
The examples in this article share with you the code for batch delete operations in php for your reference. The details are as follows:
1. Batch Delete page 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) "/> Code </td> <td> name </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 = "batch Delete"/> </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>
Referenced encapsulation class DBDA. class1.php
<? Phpclass DBDA {public $ host = "localhost"; public $ uid = "root"; public $ pwd = "123"; public $ dbname = "test_123 "; // execute the SQL statement and return the corresponding result // $ SQL statement to be executed // $ type indicates the type of the SQL statement, and 0 indicates addition, deletion, and modification, 1 indicates querying function query ($ SQL, $ type = 1) {$ db = new MySQLi ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname); $ result = $ db-> query ($ SQL); if ($ type) {// if it is a query, show data return $ result-> fetch_all ();} else {// If adding, deleting, modifying, return true or false return $ result ;}}}
2. Delete the processing interface 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");}
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.