這篇文章給大家分享的是有關(guān)php如何實(shí)現(xiàn)批量刪除操作的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

批量刪除多條記錄,對(duì)于比較多的信息,如果沒(méi)有批量刪除功能是非常麻煩的。
1.從數(shù)據(jù)庫(kù)中拿一張表過(guò)來(lái),寫個(gè)復(fù)選框進(jìn)行選擇
可以加全選復(fù)選框
連接數(shù)據(jù)庫(kù)什么的都不寫啦
代碼:
<form action="piliangshanchu.php" method="post" >
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="200">
<input type="checkbox" value="''" name="dx" onclick="checkall(this)" />
編號(hào)</td>
<td width="200">姓名</td>
<td width="200">電話</td>
<td width="200" >分組</td>
<td width="200" >操作</td>
</tr>
<tr>
<td>
<input type='checkbox' value='{$attr[0]}' name='item[]' class='ck' />
{$attr[0]}</td>
<td>{$str}</td>
<td>{$attr[2]}</td>
<td>{$nation}</td>
</tr>
</table>
<input type="submit" value="批量刪除"/>
</form>外加一個(gè)批量刪除按鈕
上圖:

我如果點(diǎn)擊全選,利用js點(diǎn)擊事件就可以輕松實(shí)現(xiàn)全選
代碼:
<script>
function xxx(qx)
{
//全選多選的選中狀態(tài)
var ck = document.getElementsByClassName("ck");
//讓下面所有的多選選中狀態(tài)改變
if(qx.checked)
{
for(i = 0;i < ck.length ; i++)
{
ck[i].setAttribute("checked","checked");
//狀態(tài)改變?yōu)檫x中
}
}
else
{
for(var i = 0;i < ck.length;i++)
{
ck[i].removeAttribute("checked");
//移除選中
}
}
}
</script>2.刪除的處理頁(yè)面
代碼:
<?php
$arr = $_POST["item"];
$db = new mysqli("localhost","root","12345678","heiheihei");
//foreach($arr as $v)
//{
// $sql = "delete from contacts WHERE id='{$v}'";
// $db->query($sql);
//}
$str = implode("','",$arr);//拼接字符,
$sql = "delete from contacts WHERE id in('{$str}')";
//2','8','4
if($db->query($sql))//判斷是否查詢成功,
{
header("location:shouye.php");
//成功就跳轉(zhuǎn)
}
?>用foreach數(shù)據(jù)傳輸過(guò)慢,刪除遍歷繁多,因此直接判斷;
感謝各位的閱讀!關(guān)于“php如何實(shí)現(xiàn)批量刪除操作”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
名稱欄目:php如何實(shí)現(xiàn)批量刪除操作-創(chuàng)新互聯(lián)
文章源于:http://chinadenli.net/article36/dooopg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、商城網(wǎng)站、App開發(fā)、網(wǎng)站維護(hù)、電子商務(wù)、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容