<?php header("content-type:text/html;charset=utf-8"); //连接数据库 $link = mysqli_connect("127.0.0.1",'root','root','08e'); //设置字符集 mysqli_query($link,'set names utf-8'); //接收传值 $ids = $_GET['ids']; $id_arr = explode(',',$ids); for ($i=0;$i<count($id_arr);$i++){ $sql = 'select * from USER WHERE id='.$id_arr[$i]; $res = mysqli_query($link,$sql); $data = mysqli_fetch_assoc($res); if($data['status']==1){ $a = '启用'; }else{ $a = '禁用'; } $content = '<table> <tr> <td>ID</td> <td>'.$data['id'].'</td> </tr> <tr> <td>账号</td> <td>'.$data['username'].'</td> </tr> <tr> <td>密码</td> <td>'.$data['password'].'</td> </tr> <tr> <td>状态</td> <td>'.$a.'</td> </tr> </table>'; file_put_contents('list-'.$id_arr[$i].'.html',$content); }
以上是php页面
表单页面:
<?php ob_start(); //if(file_exists('list.html')){ // //直接拿来用 // $content = file_get_contents("list.html"); // echo $content; // die; //} header("content-type:text/html;charset=utf-8"); //链接数据库 $link = mysqli_connect("127.0.0.1",'root','root','08e'); //设置字符集 mysqli_query($link,'set names utf-8'); //拼接sql $sql = "select * from user"; //执行 $res = mysqli_query($link,$sql); while($a = mysqli_fetch_assoc($res)){ $data[] = $a; } ?> <table> <tr> <th>选择</th> <th>ID</th> <th>账号</th> <th>密码</th> <th>状态</th> <th>操作</th> </tr> <?php foreach($data as $k=>$v){ ?> <tr> <td><input type="checkbox" name="check" value="<?php echo $v['id'];?>"></td> <td><?php echo $v['id'];?></td> <td><?php echo $v['username'];?></td> <td><?php echo $v['password'];?></td> <td><?php if($v['status']==1){ echo "启用"; }else{ echo "禁用"; } ?></td> <td> <a href="list-<?php echo $v['id'];?>.html">详情</a> </td> </tr> <?php } ?> </table> <button id="cli">一键生成静态页</button> <script src="jquery-3.3.1.min.js"></script> <script> $(document).on('click','#cli',function () { var check = document.getElementsByName('check'); var arr = []; for(var i=0;i<check.length;i++){ if(check[i].checked==true){ arr.push(check[i].value); } } var ids = arr.toString(); $.get("AllStatic.php?ids="+ids,function (data) { alert('已执行加载'); }); }); </script> <?php //获取缓存内容 $content = ob_get_contents(); //写入缓存文件 file_put_contents("list.html",$content); ob_end_flush(); ?>