触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > php 分页、全选、反选、全不选、批量删除 .
  1. <?php  
  2. /** 
  3.  * 用户管理 
  4.  * 2011/8/22 
  5.  * kcj 
  6.  *  
  7.  * */  
  8. include "isLogin.php";  
  9. include "../conn/conn.php";  
  10. $sql="select * from user";  
  11. $rst=mysql_query($sql);  
  12. $totalnum=mysql_num_rows($rst);  
  13. $pagesize=5;  
  14. $page=$_GET['page'];  
  15. if($page==''){  
  16.     $page=1;  
  17. }  
  18. $begin=($page-1)*$pagesize;  
  19. $pagecount=ceil($totalnum/$pagesize);  
  20. ?>  
  21.   
  22.   
  23. <html>  
  24.     <head>  
  25.         <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  26.         <title>无标题文档</title>  
  27.         <meta name="Author" content="kcj" />  
  28.         <meta name="Keywords" content="php,kcj" />  
  29.         <link rel="stylesheet" type="text/css" href="style/lampcms.css">  
  30.         <script src="javascript/common0.js"></script>  
  31.         <script type="text/javascript">  
  32.           var checkall=document.getElementsByName("dell[]");  
  33.             function select(){                          //全选   
  34.                 for(var $i=0;$i<checkall.length;$i++){  
  35.                     checkall[$i].checked=true;  
  36.                 }  
  37.             }  
  38.             function fanselect(){                        //反选   
  39.                 for(var $i=0;$i<checkall.length;$i++){  
  40.                     if(checkall[$i].checked){  
  41.                         checkall[$i].checked=false;  
  42.                     }else{  
  43.                         checkall[$i].checked=true;  
  44.                     }  
  45.                 }  
  46.             }           
  47.             function noselect(){                          //全不选   
  48.                 for(var $i=0;$i<checkall.length;$i++){  
  49.                     checkall[$i].checked=false;  
  50.                 }  
  51.             }  
  52.           
  53.         </script>  
  54.           
  55.           
  56.     </head>  
  57.     <body>  
  58.         <div id="main">  
  59.             后台管理->管理用户  
  60.             <form  method="post" action="" onsubmit="return confirm('你确定要删除选中项吗?')"  >  
  61.             <div class="msg-box">  
  62.                 <ul class="viewmess">  
  63.                     <li class="dark-row">  
  64.                         <span class="list_width width_font">用户名</span>  
  65.                         <span class="list_width width_font" style="width:200px">备注名</span>  
  66.                         <span class="list_width width_font">注册时间</span>  
  67.                         <span class="list_width width_font">操  作</span>  
  68.                     </li>  
  69.                          <?php  
  70.                            
  71.                          if(isset($_POST['dell'])){       //批量删除   
  72.                             $ids=$_POST['dell'];  
  73.                             $ids=implode(","$ids);   //implode函数 把数组元素组合为一个字符串。   
  74.                             $sql="delete from user where id in ($ids)";  
  75.                             mysql_query($sql);  
  76.                          }  
  77.                            
  78.                          if(isset($_GET['del'])){  
  79.                             $id=$_GET['del'];  
  80.                             $sql="delete from user where id=".$id;  
  81.                             mysql_query($sql);  
  82.                          }  
  83.                            
  84.                            
  85.                          $sql="select * from user order by id limit $begin,$pagesize";  
  86.                          $rst=mysql_query($sql);  
  87.                          while ($row=mysql_fetch_array($rst)){  
  88.                            
  89.                          ?>  
  90.                         <li class="light-row" style="padding-top:2px; padding-bottom:2px">  
  91.                               
  92.                           
  93.                     <span class="list_width" style="width:200px"><?php if($row['id']!=1){?><input type="checkbox" name="dell[]"  value="<?php echo $row['id']?>">   <?php }?>  
  94.                             <?php echo $row['username']?></span>  
  95.                             <span class="list_width"><?php echo $row['rname']?></span>  
  96.                              <span class="list_width"><?php echo substr($row['ctime'],0,10)?></span>  
  97.                             <span class="list_width" style="width:160px;">  
  98.                           
  99.                             【<a href="editUser.php?edit=<?php echo $row['id']?>">修改</a>】  
  100.                           <?php if($row['id']!=1){?>  
  101.                             【<a onclick="return confirm('确定要删除用户<?php echo $row['username']?>吗?')" href="listUser.php?del=<?php echo $row['id']?>">删除</a>】  
  102.                             <?php  
  103.                          }  
  104.                             ?>  
  105.                             </span>  
  106.                         <?php   
  107.                          }  
  108.                         ?>  
  109.                       
  110.                           
  111.                       
  112.                     <li class="dark-row">  
  113.                         <span class="col_width" style="margin-left:15px;width:240px">   
  114.                             <a href="javascript:select()">全选</a>/<a href="javascript:fanselect()">反选</a>/<a href="javascript:noselect()">全不选</a>  选中项:   
  115.                               
  116.                             <input  name="dels" type="image" title="删除" value="delete" src="images/delete.gif">    
  117.                          </span>  
  118.                         <span class="right">  
  119.                             共 <b><?php echo $totalnum?></b> 个用户,共<?php echo $pagecount;?>页  
  120.                             <a href="<?php echo $_SERVER['PHP_SELF']."?page=1"?>">首页</a>  
  121.         
  122.                             <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php if($page<1) echo $page-1;else echo $page=1;?>">上一页</a>  
  123.                             <?php  
  124.                             for($i=1;$i<=$pagecount;$i++){    //$i<=$pagecount(必须是<=)   
  125.                                 echo "<a href=".$_SERVER['PHP_SELF']."?page=$i".">[".$i."]</a>";  
  126.                             }  
  127.                               
  128.                             ?>  
  129.                             <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?PHP if($page<$pagecount-1) echo $page+1; else echo $pagecount;?>">下一页</a>  
  130.                             <a href="<?php echo $_SERVER['PHP_SELF']."?page={$pagecount}"?>">尾页</a>  
  131.                         </span>  
  132.                     </li>  
  133.                 </ul>   
  134.             </div>  
  135.                     </form>  
  136.         </div>  
  137.     </body>  

来源:http://blog.csdn.net/china_skag/article/details/7311714

  1. </html>  

工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com