大家可以參考下面的這篇文章http://www.jb51.net/article/6488.htm
SQL:$SQL="delete from `doing` where id in ('1,2,3,4')";
資料用逗號隔開。
表單:
複製代碼 代碼如下:
好$ID_Dele=$_POST['ID_Dele']將會是一個數組,雖然說PHP是弱類型的,但這裡可沒ASP弱。
ASP可以直接:
SQL="delete from [doing] where id in ('"&ID_Dele&"')"進行刪除。但PHP不能把$ID_Dele直接放進去。因為$ID_Dele可不是'1,2,3,4'哦,因為$ID_Dele是一個數組,具有鍵和值。
好,PHP中也不難,剛好有個函數:implode(),對了。同split()explode()功能剛好相反的一個函數,後兩者是用某字元(比如逗號)分割的,而前者則可以拼接為字串。
因此:
複製代碼 代碼如下:
$ID_Dele= implode(",",$_POST['ID_Dele']);
$SQL="delete from `doing` where id in ($ID_Dele)";
指令碼之家提供測試代碼:
複製代碼 代碼如下:
if ($_POST["action"]="doing"){
$del_id=$_POST["ID_Dele"];
$ID_Dele= implode(",",$_POST['ID_Dele']);
echo "合并後:".$ID_Dele."
合并前:";
if($del_id!=""){
$del_num=count($del_id);
for($i=0;$i<$del_num;$i++){
echo $del_id[$i];
}
}
}else{
echo "請提交";
}
?>
http://www.bkjia.com/PHPjc/320728.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320728.htmlTechArticle大家可以參考下面的這篇文章http://www.jb51.net/article/6488.htm SQL:$SQL="delete from `doing` where id in ('1,2,3,4')"; 資料用逗號隔開。 表單: 複製代碼...