欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP 批量刪除數(shù)據(jù)的方法分析

 更新時(shí)間:2009年10月30日 19:44:12   作者:  
好多朋友在網(wǎng)站開發(fā)中,經(jīng)常需要批量刪除數(shù)據(jù),尤其是習(xí)慣了asp的朋友,更是感覺asp下真方便了,php下什么都是數(shù)組有點(diǎn)麻煩。
大家可以參考下面的這篇文章http://www.dbjr.com.cn/article/6488.htm
SQL:$SQL="delete from `doing` where id in ('1,2,3,4')";
  數(shù)據(jù)用逗號隔開。
  表單:
復(fù)制代碼 代碼如下:

  <form action="?action=doing" method="post">
  <input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="1"/>
  <input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="2"/>
  <input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="3"/>
  <input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="4"/>
  <input type="submit"/>
  </form>

  好$ID_Dele=$_POST['ID_Dele']將會(huì)是一個(gè)數(shù)組,雖然說PHP是弱類型的,但這里可沒ASP弱。
  ASP可以直接:
  SQL="delete from [doing] where id in ('"&ID_Dele&"')"進(jìn)行刪除。但PHP不能把$ID_Dele直接放進(jìn)去。因?yàn)?ID_Dele可不是'1,2,3,4'哦,因?yàn)?ID_Dele是一個(gè)數(shù)組,具有鍵和值。
  好,PHP中也不難,剛好有個(gè)函數(shù):implode(),對了。同split()explode()功能剛好相反的一個(gè)函數(shù),后兩者是用某字符(比如逗號)分割的,而前者則可以拼接為字符串。
  因此:
復(fù)制代碼 代碼如下:

  $ID_Dele= implode(",",$_POST['ID_Dele']);
  $SQL="delete from `doing` where id in ($ID_Dele)";


腳本之家提供測試代碼:
復(fù)制代碼 代碼如下:

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<?php
if ($_POST["action"]="doing"){
$del_id=$_POST["ID_Dele"];
$ID_Dele= implode(",",$_POST['ID_Dele']);
echo "合并后:".$ID_Dele."<br />合并前:";
if($del_id!=""){
$del_num=count($del_id);
for($i=0;$i<$del_num;$i++){
echo $del_id[$i];
}
}
}else{
echo "請?zhí)峤?;
}

?>
<form action="?action=doing" method="post">
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="第1個(gè)"/>第1個(gè)
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="第2個(gè)"/>第2個(gè)
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="第3個(gè)"/>第3個(gè)
<input name="ID_Dele[]" type="checkbox" id="ID_Dele[]" value="第4個(gè)"/>第4個(gè)
<input type="submit"/>
</form>

相關(guān)文章

最新評論