Analysis of methods to delete data in batches with PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:43:34
Original
856 people have browsed it

You can refer to the following article http://www.jb51.net/article/6488.htm
SQL: $SQL="delete from `doing` where id in ('1,2,3,4' )";
Data is separated by commas.
Form:

Copy code The code is as follows:


 
 
 
 
  


Good $ID_Dele=$_POST['ID_Dele'] will be an array. Although PHP is weakly typed, it is not as weak as ASP.
ASP can directly:
SQL="delete from [doing] where id in ('"&ID_Dele&"')" to delete. But PHP cannot put $ID_Dele directly into it. Because $ID_Dele is not '1,2,3,4', because $ID_Dele is an array with keys and values.
Okay, it’s not difficult in PHP. There happens to be a function: implode(), right. A function that has exactly the opposite function to split()explode(). The latter two are separated by a certain character (such as a comma), while the former can be spliced ​​into a string.
Therefore:
Copy code The code is as follows:

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


Script House provides test code:
Copy code The code is as follows:


if ($_POST["action"]="doing"){
$del_id=$_POST["ID_Dele"];
$ID_Dele= implode( ",",$_POST['ID_Dele']);
echo "After merge:".$ID_Dele."
Before merge:";
if($del_id!="") {
$del_num=count($del_id);
for($i=0;$i<$del_num;$i++){
echo $del_id[$i];
}
}
}else{
echo "Please submit";
}

?>
1st
2nd
3rd
The 4th


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320728.htmlTechArticleYou can refer to the following article http://www.jb51.net/article/6488.htm SQL :$SQL="delete from `doing` where id in ('1,2,3,4')"; The data is separated by commas. Form: Copy code...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!