public function shows(Request $request){ $p=$request->get("page"); $page=empty($p)?1:$p; $count=DB::table("shop")->count(); $length = 4; $num_page = ceil($count/$length); $limit = ($page-1)*$length; $data=DB::select("select * from shop limit $limit,$length"); $arr[‘data‘]=$data; $arr[‘home_page‘] = 1; $arr[‘prev_page‘] = $page-1<=1?1:$page-1; $arr[‘next_page‘] = $page+1>=$num_page?$num_page:$page+1; $arr[‘last_page‘] = $num_page; return view("/index/month/shows",[‘list‘=>$arr]); }
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <center> <form action="/index/month/search" method="post"> <input type="text" name="goods"> <input type="submit" value="搜索"> </form> <table border="3"> <tr> <td>ID</td> <td>商品</td> <td>积分</td> <td>操作</td> </tr> <?php foreach ($list[‘data‘] as $key=>$v) {?> <tr> <td><?php echo $v->id ?></td> <td><?php echo $v->goods ?></td> <td><?php echo $v->socre ?></td> <td><a href="/index/month/buy?goods=<?php echo $v->goods ?>&socre=<?php echo $v->socre ?>"><button>点击购买</button></a></td> </tr> <?php }?> </table> <a href="javascript:void(0);" onclick="page({{$list[‘home_page‘]}})">首页</a> <a href="javascript:void(0);" onclick="page({{$list[‘prev_page‘]}})">上一页</a> <a href="javascript:void(0);" onclick="page({{$list[‘next_page‘]}})">下一页</a> <a href="javascript:void(0);" onclick="page({{$list[‘last_page‘]}})">尾页</a> </center> </body> </html> <script src="/js/jquery.js"></script> <script> function page(obj){ $.get("/index/month/shows?page="+obj, function(data){ $("body").html(data); } ); } </script>
原文地址:https://www.cnblogs.com/yingyong/p/10766666.html
时间: 2024-11-05 18:50:49