12-29 Bulk Delete

Source: Internet
Author: User

<form action= "shanchu.php" method= "POST" >
<table width= "100%" border= "1" cellpadding= "0" cellspacing= "0" >
<tr>
<td><input type= "checkbox" id= "QX" onclick= "Xuanzhong ()"/> Select all </td>
<td> Code </td>
<td> name </td>
</tr>

<?php
Include (".. /fengzhuang/dbda.class.php ");
$db = new Dbda ();

$sql = "SELECT * From Nation";
$attr = $db->query ($sql);

foreach ($attr as $v)
{
echo "<tr>
<td><input type= ' checkbox ' name= ' ck[] ' class= ' ck ' value= ' {$v [0]} '/></td>
<td>{$v [0]}</td>
<td>{$v [1]}</td>
</tr> ";
}

?>

</table>
<input type= "Submit" value= "delete" onclick= "return Tishi ()"/>
</form>
</body>
<script type= "Text/javascript" >
function Xuanzhong ()
{
Select All selected Buttons
var zt = document.getElementById ("QX"). Checked;

Let all of the checkboxes in the following check state change
var ck = document.getelementsbyclassname ("ck");

for (Var i=0;i<ck.length;i++)
{
if (ZT)
{
Ck[i].setattribute ("Checked", "checked");
}
Else
{
Ck[i].removeattribute ("checked");
}
}
}

function Tishi ()
{
Find All Selected items
var ck = document.getelementsbyclassname ("ck");

var str = "";

for (Var i=0;i<ck.length;i++)
{
if (ck[i].checked)
{
str + = ck[i].value+ ",";
}
}

return confirm ("OK to delete the following data:" +str+ "");
}
</script>

Effect:

Delete Page

<?php
$ck = $_post["ck"];

Include (".. /fengzhuang/dbda.class.php ");
$db = new Dbda ();

The first way
/*foreach ($ck as $v)
{
$sql = "Delete from Nation where code= ' {$v} '";
$db->query ($sql, 0);
}*/

The second way
In (",", ",", ",")
$str = Implode ("', '", $ck);

$str = "(' {$str} ')";

$sql = "Delete from Nation where code in {$str}";
$db->query ($sql, 0);

Header ("location:main.php");

12-29 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.