PHP jQuery + Ajax combined with the write batch delete function, jqueryajax
For the sake of beauty, I introduced the bootstrap modal box. I introduced a table named maninfo in my database library, which is a personal information table.
I will not write about table loading. It is relatively simple. Just write the required buttons and html sections.
<Button type = "button" class = "btn-primary" id = "plsp_z"> batch Delete </button>
Select All:
<input type="checkbox" id="cq"/>
The displayed check box is
<input type="checkbox" value="{$v[0]}" class="cq"/>
First, after clicking the Select All button, you can select all the check boxes for traversal.
<script type="text/javascript"> $("#cq").click(function(){$(".cq").prop("checked",$(this).prop("checked"));})</script>
Here I only wrote a simple modal box
<Div class = "modal fade" id = "myModal11" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" aria-hidden = "true"> <div class = "modal-dialog"> <div class = "modal-content"> <div class = "modal-header"> <button type = "button" class = "close "data-dismiss =" modal "aria-hidden =" true "> × </button>
In this way, the front-end content is complete, and the js part is written. All I use is jquery.
Var chk = ""; var check2 = ""; // determine whether one of the multiple check boxes is implemented by function checked () {var count = 0; var checkx = $ ("# cq"); if (checkx. checked) {check2 = 1; // select the Select All button} else {check2 = 0; // the Select All button is not selected} var checkArry = $ (". cq "); for (var I = 0; I <checkArry. length; I ++) {if (checkArry [I]. checked = true) {// The selected Operation count ++ ;}} if (count = 0) {chk = 0; // No selected items} else {chk = 1; // selected items} // alert (chk);} function plscdzxx () {// batch Delete $ ("# plsp_z "). click (function () {checked (); if (chk = 1 | check2 = 1) {// submit $ ('# myModal12 '). modal ('show'); $ ("# nqrplsc "). click (function () {/* add an event to the confirm deletion button */$ ('# myModal12 '). modal ('hide '); // find the selected primary key value, and traverse the selected primary key value in a loop var cq = $ (". cq "); var plstr =" "; for (var I = 0; I <cq. length; I ++) {if (cq. eq (I ). prop ("checked") {plstr + = cq. eq (I ). val () + "','" ;}} plstr = plstr. substr (0, plstr. length-3); // The delimiter occupies 3 characters. The string is truncated and the last "','" is removed. This matches the SQL statement $. ajax ({async: false, url: "plsp_z. php ", data: {plstr: plstr}, dataType:" TEXT ", type:" POST ", success: function (data) {if (data. trim () = "OK") {alert ("deleted successfully"); nload (); // re-load the page here} else {alert ("failed to delete") ;}}}) ;};} else if (chk = 0) {// do not submit // alert (chk); alert ("select the content you want to delete ");}})}
Ajax will connect to the batch deletion processing page. below is the batch deletion processing page
<?phpsession_start();include("DBDA.class.php");$db = new DBDA();if(!empty($_POST["plstr"])){ $plstr = $_POST["plstr"]; $sql = "delete from maninfo where id in ('{$plstr}')"; if($db->Query($sql,0)) { echo "OK"; } else { echo "NO"; }}
Write it here. If you try it yourself, you may not run it. In this case, you need to call the batch deletion method. If there is a previous loading method, then you can directly write the batch deletion method to the loading method and call it.
The above is a small series of PHP jQuery + Ajax combined with the write batch delete function, I hope to help you, if you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!