php批量删除数据

yipeiwu_com6年前PHP代码库
批量删除文章这个技术没什么高深莫测的,只是想写下来与大家分享。(适合初学者:)
1、首先在文章列表页面(list.php),将多选筐命名为:“$del_id[]”,值为文章ID号。
     例如(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>
2、处理页面(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='$del_id[$i]'");
             } 
             echo("<script type='text/javascript'>alert('删除成功!');history.back();</script>");
      }else{
             echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");
      }
    ?>  

相关文章

Windows下XDebug 手工配置与使用说明

1. 下载XDebug二进制文件: http://www.xdebug.org/download.php   5.2 http://www.xdebug.org/files/php_xd...

PHP-CGI进程CPU 100% 与 file_get_contents 函数的关系分析

后来,我通过跟踪发现,这类情况的出现,跟 PHP 的 file_get_contents() 函数有着密切的关系。   大、中型网站中,基于 HTTP 协议的 API 接口调用,是家常便...

PHP 获取ip地址代码汇总

代码一: function getip() { static $ip = ''; $ip = $_SERVER['REMOTE_ADDR']; if(isset($_SE...

PHP数据库表操作的封装类及用法实例详解

本文实例讲述了PHP数据库表操作的封装类及用法。分享给大家供大家参考,具体如下: 数据库表结构: CREATE TABLE `test_user` ( `id` int(11) NO...

解析PHP将对象转换成数组的方法(兼容多维数组类型)

复制代码 代码如下: /**  * @author 【宜配屋www.yipeiwu.com】  * @date 2013-6-21  * @tod...