$delete = $_POST['delete']; // POST方式獲得復(fù)選框值
10年的略陽網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整略陽建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“略陽網(wǎng)站設(shè)計(jì)”,“略陽網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
//單擊刪除按鈕時(shí)
if ($submitdel) // 按提交按鈕
{
//以,號組合成字符串,供mysql使用
$aryid=@implode(",",$delete);
$db-query("delete from `table` where id in($aryid)");
}
復(fù)選框的大致代碼:
input type="checkbox" name="delete[]" value="?php echo $id; ?"
原理:復(fù)選框的name屬性為delete[] 所以選擇如果個(gè)之后獲得的$delete值為一個(gè)數(shù)組,例如是$delete = array(0 = 1,1 = 2,2 = 3);
然后用implode函數(shù)將數(shù)組切割成字符串,$aryid=@implode(",",$delete);那么$aryid就是 $aryid = "1,2,3";
然后執(zhí)行sql語句。delete from `table` where id in($aryid)
SQL語句就是delete from `table` where id in(1,2,3);
這樣就很明白了吧
//刪除是記錄是用sql語句,比如 delete from xxx(table) where id=1 刪除 id=1的記錄
//數(shù)據(jù)庫操作后,手動關(guān)閉是好得習(xí)慣,不手動關(guān)閉,php程序也會最后自動關(guān)閉
$cars=array("Volvo","BMW","Toyota","BMW","23","33","23","67","23");
$cars2 = array_unique($cars);//元素去重
$cars2 = array_merge_recursive($cars2);//合并(因?yàn)槿ブ睾笏饕柌恢匦抡恚?/p>
$delCars = array_splice($cars2,1,2);//從數(shù)組中移除索引號1開始共計(jì)2個(gè)元素
array_splice($cars2,0,(count($cars2)));//清空數(shù)組內(nèi)容
unset($cars2);//或 $cars2 = null ,刪除數(shù)組