Case: Bulk Delete

Source: Internet
Author: User

A little knowledge:

1, PHP access to the database, additions and deletions to the database, the page display results = Database results

2, <radio><checkbox><option> label, Name= "xx[]", which indicates how many commits are selected and submitted as an array, which can be obtained in array form.

Value values are defined by themselves, with different <text> value.

The value is obtained by the name submission.

Bulk Delete:

Click the button to achieve bulk deletion, need a form form, need a batch processing page (also can put the same page, but also need to add code, to achieve the initial effect).

Main Page code:

<form action= "plsc.php" method= "post" &GT;&LT;?PHP$db=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sql= "SELECT * FROM Info";$result=$db->query ($sql);$attr=$result-Fetch_all ();foreach($attr  as $v){    $s=$v[2]==1? ' Male ': ' Female '; $sq= "SELECT name from Nation where Code= ' {$v[3]} ' "; $r=$db->query ($sq); $a=$r-Fetch_row (); Echo"<tr> <td align= ' center ' ><input type= ' checkbox ' name= ' xx[] ' value= '$v[0] ' class= ' a '/>{$v[0]}</td> <td align= ' center ' >{$v[1]}</td> <td align= ' center ' >{$s}</td> <td align= ' center ' >{$a[0]}</td> <td align= ' center ' >{$v[4]}</td> <td align= ' center ' ><a href= ' delete.php?code={$v[0]} ' > Delete </a> <a href= ' update.php?code={$v[0]} ' > Modify </a> </td> </tr>";}&GT;&LT;TR&GT;&LT;TD align= "center" ><input type= "checkbox" onclick= "Checkall (This)"/> Select all </td></ TR&GT;&LT;TR&GT;&LT;TD align= "center" ><input type= "submit" value= "Bulk Delete"/></td></tr></form >

Processing page:

<?PHPHeader("Content-type:text/html;charset=utf-8");if(!Empty($_post)){    $xx=$_post["XX"];//one-dimensional arrays    Var_dump($xx); //Operational Database Removal    $db=NewMysqli ("localhost", "root", "123", "info"); !Mysqli_connect_error() or die("Connection Failed"); //choose which one to delete the article    /*foreach ($xx as $v) {$sql = "Delete from info where code= ' {$v} '";        $result = $db->query ($sql, 0); }*/     for($i= 0;$i<=Count($xx);$i++)        {            $sql= "Delete from info where code= ' {$xx[$i]}‘"; Var_dump($sql); $result=$db->query ($sql); Var_dump($result); }        if($result)        {            Header("location:main.php"); }    Else        {            Echo"Bulk Delete Failed"; }}

Case: Bulk Delete

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.