Jquery+php simple implementation of all-choice deletion method _php skill

Source: Internet
Author: User
Tags getting started with php php database

The example of this article describes the jquery+php simple implementation of the total selection of deletion method. Share to everyone for your reference, specific as follows:

<input type= "checkbox" id= "Ckb_selectall" onclick= "SelectAll ()" title= "Check/uncheck" >
<a href= "javascript: void (0); "onclick=" Del_ () title= "Delete selected data" style= "font-weight:normal" > Delete </a>

↑ All Select checkbox

<input type= "checkbox" class= "ckb" id= "+con.id+" value= "+con.id+" >

↑ for deletion item, the same name class is CKB, convenient to operate, at the same time the ID value cleverly put into input, easy to obtain.

function SelectAll () {
  if ($ (' #ckb_selectAll '). Is (': Checked ') {
    $ (". ckb"). attr ("Checked", true);//All selected
  } else {
    $ (". ckb"). attr ("checked", false);//Cancel All
  }
}

↑ Selected Events

function Del_ () {
  var ids = ';
  $ (". ckb"). each (the function () {
    if ($ (). Is (': Checked ')) {
      ids + = ', ' + $ (this). Val ();//Get ID one by one
    }
  });
  ids = ids.substring (1); The ID is processed to remove the first comma
  if (ids.length = 0) {
    alert (' Please select the option to delete ');
  } else {
    If confirm ("OK delete?"). You will not be able to recover after deletion. ")" {
      URL = "action=del_call_record&ids=" + IDs;
      $.ajax ({
        type: "Post",
        URL: "send.php",
        Data:url,
        success:function (JSON) {
          if parseint ( Json.counts) > 0) {
            alert (json.des);
            Location.reload ();
          } else {
            alert (json.des);
          }
        },
        error:function (XMLHttpRequest, textstatus) {
          alert ("Page request error, Please check to try again or contact admin! \ n "+ Textstatus);}}";}}


↑ Delete with Ajax to process.

↓ Background operation database, processing delete action.

$ids = Trim ($_request[' IDs ']);
$del _sql = "DELETE from Vicidial_call_record WHERE ID in (". $ids. ");
Print_r ($del _sql); exit;
if (Mysqli_query ($db _conn, $del _sql)) {
  $counts = "1";
  $des = "Success";
} else {
  $counts = "0";
  $des = "Failed";
}
$json _data = "{";
$json _data. = "\" counts\ ":". Json_encode ($counts). ",";
$json _data. = "\" des\ ":". Json_encode ($des). "";
$json _data. = "}";
echo $json _data;
Break

Complete

For more information about PHP interested readers can view the site topics: "Php+ajax Skills and Application Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP object-oriented Program Design Introductory Course", "PHP string (String) Usage Summary", "Getting Started with Php+mysql database operations" and "Summary of common PHP database Operations skills"

I hope this article will help you with the PHP program design.

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.