程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 分頁、全選、反選、全不選、批量刪除

php 分頁、全選、反選、全不選、批量刪除

編輯:關於PHP編程

<?php 
/**
 * 用戶管理
 * 2011/8/22
 * kcj
 * 
 * */ 
include "isLogin.php"; 
include "../conn/conn.php"; 
$sql="select * from user"; 
$rst=mysql_query($sql); 
$totalnum=mysql_num_rows($rst); 
$pagesize=5; 
$page=$_GET['page']; 
if($page==''){ 
    $page=1; 

$begin=($page-1)*$pagesize; 
$pagecount=ceil($totalnum/$pagesize); 
?> 
 
 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
        <title>無標題文檔</title> 
        <meta name="Author" content="kcj" /> 
        <meta name="Keywords" content="php,kcj" /> 
        <link rel="stylesheet" type="text/css" href="style/lampcms.css"> 
        <script src="javascript/common0.js"></script> 
        <script type="text/javascript"> 
          var checkall=document.getElementsByName("dell[]"); 
            function select(){                          //全選  
                for(var $i=0;$i<checkall.length;$i++){ 
                    checkall[$i].checked=true; 
                } 
            } 
            function fanselect(){                        //反選  
                for(var $i=0;$i<checkall.length;$i++){ 
                    if(checkall[$i].checked){ 
                        checkall[$i].checked=false; 
                    }else{ 
                        checkall[$i].checked=true; 
                    } 
                } 
            }          
            function noselect(){                          //全不選  
                for(var $i=0;$i<checkall.length;$i++){ 
                    checkall[$i].checked=false; 
                } 
            } 
         
        </script> 
         
         
    </head> 
    <body> 
        <div id="main"> 
            後台管理->管理用戶 
            <form  method="post" action="" onsubmit="return confirm('你確定要刪除選中項嗎?')"  > 
            <div class="msg-box"> 
                <ul class="viewmess"> 
                    <li class="dark-row"> 
                        <span class="list_width width_font">用戶名</span> 
                        <span class="list_width width_font" style="width:200px">備注名</span> 
                        <span class="list_width width_font">注冊時間</span> 
                        <span class="list_width width_font">操  作</span> 
                    </li> 
                         <?php 
                          
                         if(isset($_POST['dell'])){       //批量刪除  
                            $ids=$_POST['dell']; 
                            $ids=implode(",", $ids);   //implode函數 把數組元素組合為一個字符串。  
                            $sql="delete from user where id in ($ids)"; 
                            mysql_query($sql); 
                         } 
                          
                         if(isset($_GET['del'])){ 
                            $id=$_GET['del']; 
                            $sql="delete from user where id=".$id; 
                            mysql_query($sql); 
                         } 
                          
                          
                         $sql="select * from user order by id limit $begin,$pagesize"; 
                         $rst=mysql_query($sql); 
                         while ($row=mysql_fetch_array($rst)){ 
                          
                         ?> 
                        <li class="light-row" style="padding-top:2px; padding-bottom:2px"> 
                             
                         
                    <span class="list_width" style="width:200px"><?php if($row['id']!=1){?><input type="checkbox" name="dell[]"  value="<?php echo $row['id']?>">   <?php }?> 
                            <?php echo $row['username']?></span> 
                            <span class="list_width"><?php echo $row['rname']?></span> 
                             <span class="list_width"><?php echo substr($row['ctime'],0,10)?></span> 
                            <span class="list_width" style="width:160px;"> 
                         
                            【<a href="editUser.php?edit=<?php echo $row['id']?>">修改</a>】 
                          <?php if($row['id']!=1){?> 
                            【<a onclick="return confirm('確定要刪除用戶<?php echo $row['username']?>嗎?')" href="listUser.php?del=<?php echo $row['id']?>">刪除</a>】 
                            <?php 
                         } 
                            ?> 
                            </span> 
                        <?php  
                         } 
                        ?> 
                     
                         
                     
                    <li class="dark-row"> 
                        <span class="col_width" style="margin-left:15px;width:240px">  
                            <a href="javascript:select()">全選</a>/<a href="javascript:fanselect()">反選</a>/<a href="javascript:noselect()">全不選</a>  選中項:  
                             
                            <input  name="dels" type="image" title="刪除" value="delete" src="images/delete.gif">   
                         </span> 
                        <span class="right"> 
                            共 <b><?php echo $totalnum?></b> 個用戶,共<?php echo $pagecount;?>頁 
                            <a href="<?php echo $_SERVER['PHP_SELF']."?page=1"?>">首頁</a> 
       
                            <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php if($page<1) echo $page-1;else echo $page=1;?>">上一頁</a> 
                            <?php 
                            for($i=1;$i<=$pagecount;$i++){    //$i<=$pagecount(必須是<=)  
                                echo "<a href=".$_SERVER['PHP_SELF']."?page=$i".">[".$i."]</a>"; 
                            } 
                             
                            ?> 
                            <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?PHP if($page<$pagecount-1) echo $page+1; else echo $pagecount;?>">下一頁</a> 
                            <a href="<?php echo $_SERVER['PHP_SELF']."?page={$pagecount}"?>">尾頁</a> 
                        </span> 
                    </li> 
                </ul>  
            </div> 
                    </form> 
        </div> 
    </body> 
</html> 
<?php
/**
 * 用戶管理
 * 2011/8/22
 * kcj
 *
 * */
include "isLogin.php";
include "../conn/conn.php";
$sql="select * from user";
$rst=mysql_query($sql);
$totalnum=mysql_num_rows($rst);
$pagesize=5;
$page=$_GET['page'];
if($page==''){
 $page=1;
}
$begin=($page-1)*$pagesize;
$pagecount=ceil($totalnum/$pagesize);
?>


<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>無標題文檔</title>
  <meta name="Author" content="kcj" />
  <meta name="Keywords" content="php,kcj" />
  <link rel="stylesheet" type="text/css" href="style/lampcms.css">
  <script src="javascript/common0.js"></script>
  <script type="text/javascript">
    var checkall=document.getElementsByName("dell[]");
      function select(){                          //全選
       for(var $i=0;$i<checkall.length;$i++){
        checkall[$i].checked=true;
       }
      }
      function fanselect(){                        //反選
       for(var $i=0;$i<checkall.length;$i++){
        if(checkall[$i].checked){
         checkall[$i].checked=false;
        }else{
         checkall[$i].checked=true;
        }
       }
      }        
      function noselect(){                          //全不選
       for(var $i=0;$i<checkall.length;$i++){
        checkall[$i].checked=false;
       }
      }
  
  </script>
  
  
 </head>
 <body>
  <div id="main">
      後台管理->管理用戶
      <form  method="post" action="" onsubmit="return confirm('你確定要刪除選中項嗎?')"  >
   <div class="msg-box">
    <ul class="viewmess">
     <li class="dark-row">
      <span class="list_width width_font">用戶名</span>
      <span class="list_width width_font" style="width:200px">備注名</span>
      <span class="list_width width_font">注冊時間</span>
      <span class="list_width width_font">操  作</span>
     </li>
             <?php
            
             if(isset($_POST['dell'])){       //批量刪除
                $ids=$_POST['dell'];
              $ids=implode(",", $ids);   //implode函數 把數組元素組合為一個字符串。
              $sql="delete from user where id in ($ids)";
              mysql_query($sql);
             }
            
             if(isset($_GET['del'])){
              $id=$_GET['del'];
              $sql="delete from user where id=".$id;
              mysql_query($sql);
             }
            
            
             $sql="select * from user order by id limit $begin,$pagesize";
             $rst=mysql_query($sql);
             while ($row=mysql_fetch_array($rst)){
            
             ?>
      <li class="light-row" style="padding-top:2px; padding-bottom:2px">
       
      
     <span class="list_width" style="width:200px"><?php if($row['id']!=1){?><input type="checkbox" name="dell[]"  value="<?php echo $row['id']?>"> <?php }?>
       <?php echo $row['username']?></span>
       <span class="list_width"><?php echo $row['rname']?></span>
                 <span class="list_width"><?php echo substr($row['ctime'],0,10)?></span>
       <span class="list_width" style="width:160px;">
      
       【<a href="editUser.php?edit=<?php echo $row['id']?>">修改</a>】
        <?php if($row['id']!=1){?>
       【<a onclick="return confirm('確定要刪除用戶<?php echo $row['username']?>嗎?')" href="listUser.php?del=<?php echo $row['id']?>">刪除</a>】
       <?php
             }
       ?>
       </span>
      <?php
             }
      ?>
     
      
     
     <li class="dark-row">
      <span class="col_width" style="margin-left:15px;width:240px">
       <a href="javascript:select()">全選</a>/<a href="javascript:fanselect()">反選</a>/<a href="javascript:noselect()">全不選</a>  選中項:
       
       <input  name="dels" type="image" title="刪除" value="delete" src="images/delete.gif"> 
       </span>
      <span class="right">
       共 <b><?php echo $totalnum?></b> 個用戶,共<?php echo $pagecount;?>頁
       <a href="<?php echo $_SERVER['PHP_SELF']."?page=1"?>">首頁</a>
  
       <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php if($page<1) echo $page-1;else echo $page=1;?>">上一頁</a>
       <?php
       for($i=1;$i<=$pagecount;$i++){    //$i<=$pagecount(必須是<=)
        echo "<a href=".$_SERVER['PHP_SELF']."?page=$i".">[".$i."]</a>";
       }
       
       ?>
       <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?PHP if($page<$pagecount-1) echo $page+1; else echo $pagecount;?>">www.2cto.com 下一頁</a>
       <a href="<?php echo $_SERVER['PHP_SELF']."?page={$pagecount}"?>">尾頁</a>
      </span>
     </li>
    </ul> 
   </div>
                    </form>
  </div>
 </body>
</html>[php] //<strong><span style="font-size:18px;">如果大家有什麼不明白,可以留下你的疑問,我將盡快給予回復!</span></strong> 


摘自 chaojie2009的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved