How to quickly delete articles in php

coldplay.xixi
Release: 2023-03-05 18:50:01
Original
1626 people have browsed it

php method to quickly delete articles: first on the article list page; then name the multi-select box "$del_id[]", the value is the article ID number; finally process the page, the code is [$del_num=count ($del_id)].

How to quickly delete articles in php

[Related learning recommendations: php programming (video)]

php method to quickly delete articles:

1. First, on the article list page (list.php), name the multi-select box :"$del_id[]", the value is the article ID number.

For example (list.php):

  <form name="del_form" action="del.php" method="post">
  <?php
        $result=mysql_query("select * from news");
        while($rs=mysql_fetch_array($result)){
     ?>
        <input name="del_id[]" type="checkbox" id="del_id[]" value="<?=$rs[id]?>" /><?=$rs[title]?>
     <?php
        }
     ?>
   </form>
Copy after login

2. Processing page (del.php):

  <?php
     if($del_id!=""){
             $del_num=count($del_id);
             for($i=0;$i<$del_num;$i++){
                 mysql_query("Delete from news where id=&#39;$del_id[$i]&#39;");
             } 
             echo("<script type=&#39;text/javascript&#39;>alert(&#39;删除成功!&#39;);history.back();</script>");
      }else{
             echo("<script type=&#39;text/javascript&#39;>alert(&#39;请先选择项目!&#39;);history.back();</script>");
      }
    ?>
Copy after login

If you want to learn more about programming, please stay tuned php training column!

The above is the detailed content of How to quickly delete articles in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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