Php batch Delete (Data Access) and php batch Delete

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.