laravel 三表统计的终极版
来源:互联网 发布:阿里云百倍故障赔偿 编辑:程序博客网 时间:2024/05/22 05:18
class IndexController extends Controller
{
//\vendor\laravel\framework\src\Illuminate\Pagination\LengthAwarePaginator.php
// public function __construct ($items,$total,$perPage,$currentPage=null,array $options=[]){
// foreach ($options as $key => $value) {
// $this->{$key}=$value;
// }
// $this->total=$total;
// $this->perPage=$perPage;
// $this->lastPage=(int) ceil($total / $perPage);
//// $this->path=$this->path!= '/' ? rtrim($this->path,'/');
// $this->currentPage=$this->setCurrentPage($currentPage,$this->pageName);
// $this->items=$items instanceof Collection ? $items : Collection::make($items);
//
// }
public function index(Request $request)
{
$name = $request->input('name');
// $where = ' WHERE 1';
// if ($name) {
// $where = ' WHERE name like ' . "'%$name%'";
// }
$paginate = 15;
$goods=Goods::select(DB::Raw('goods.*,COUNT(goods_nexus.rfid) as nums,goods_class.class_name'))
->leftjoin('goods_nexus','goods_nexus.goods_id','=','goods.id')
->leftjoin('goods_class','goods_class.id','=','goods.class_id')
->groupBy('goods.id')->where('name', 'like', '%' . $name . '%')->paginate($paginate);
// dd($goods);
$count =Goods::where('name', 'like', '%' . $name . '%')->count();
$total_page = ceil($count / $paginate); //共多少页
// $goods = DB::select('SELECT COUNT(gn.rfid) as nums,pro.* FROM goods_nexus
// as gn RIGHT JOIN (SELECT g.* ,gc.class_name FROM goods as
// g LEFT JOIN goods_class as gc ON g.class_id = gc.id)as pro ON
// pro.id = gn.goods_id ' . $where . ' GROUP BY pro.id ASC ');
// $total = count($goods);
// $goodslist = new \Illuminate\Pagination\LengthAwarePaginator($goods, $total, 10);
// $total_page = ceil($total / 10);
// dd($goods);
return view('index',[
'name' => $name,
'total_page'=>$total_page,
])
->with('goods', $goods);
// ->with('goods', $goodslist)->with('total_page', $total_page);
}
}
{
//\vendor\laravel\framework\src\Illuminate\Pagination\LengthAwarePaginator.php
// public function __construct ($items,$total,$perPage,$currentPage=null,array $options=[]){
// foreach ($options as $key => $value) {
// $this->{$key}=$value;
// }
// $this->total=$total;
// $this->perPage=$perPage;
// $this->lastPage=(int) ceil($total / $perPage);
//// $this->path=$this->path!= '/' ? rtrim($this->path,'/');
// $this->currentPage=$this->setCurrentPage($currentPage,$this->pageName);
// $this->items=$items instanceof Collection ? $items : Collection::make($items);
//
// }
public function index(Request $request)
{
$name = $request->input('name');
// $where = ' WHERE 1';
// if ($name) {
// $where = ' WHERE name like ' . "'%$name%'";
// }
$paginate = 15;
$goods=Goods::select(DB::Raw('goods.*,COUNT(goods_nexus.rfid) as nums,goods_class.class_name'))
->leftjoin('goods_nexus','goods_nexus.goods_id','=','goods.id')
->leftjoin('goods_class','goods_class.id','=','goods.class_id')
->groupBy('goods.id')->where('name', 'like', '%' . $name . '%')->paginate($paginate);
// dd($goods);
$count =Goods::where('name', 'like', '%' . $name . '%')->count();
$total_page = ceil($count / $paginate); //共多少页
// $goods = DB::select('SELECT COUNT(gn.rfid) as nums,pro.* FROM goods_nexus
// as gn RIGHT JOIN (SELECT g.* ,gc.class_name FROM goods as
// g LEFT JOIN goods_class as gc ON g.class_id = gc.id)as pro ON
// pro.id = gn.goods_id ' . $where . ' GROUP BY pro.id ASC ');
// $total = count($goods);
// $goodslist = new \Illuminate\Pagination\LengthAwarePaginator($goods, $total, 10);
// $total_page = ceil($total / 10);
// dd($goods);
return view('index',[
'name' => $name,
'total_page'=>$total_page,
])
->with('goods', $goods);
// ->with('goods', $goodslist)->with('total_page', $total_page);
}
}
阅读全文
0 0
- laravel 三表统计的终极版
- Laravel统计一段时间间隔的数据
- 2016 版 Laravel 系列入门教程(三)【最适合中国人的 Laravel 教程】
- laravel的原生子查询,用来统计3张表的相关数据
- 三鹿事件的终极狂想
- Laravel的三种安装方法总结
- laravel的基础学习(三)
- Laravel数据库操作的三种方式
- Laravel数据库操作的三种方式
- Laravel数据库操作的三种方式
- Laravel数据库操作的三种方式
- Laravel数据库操作的三种方式
- Laravel数据库操作的三种方式
- 三表查询、统计
- laravel(三)-laravel路由
- pandas 终极版4:DataFrame统计、合并、分组操作
- ABAP - 内表行数统计的三种方法
- 统计内表行数常用的三种方法
- 模拟实现strcpy,strcmp,strcat,strstr.strlen
- 高性能JavaScript DOM编程
- 请编写一个c函数,该函数给出一个字节中被置为1的位的个数
- ks.cfg文件参数详解
- Android逆向调试工具
- laravel 三表统计的终极版
- Linux-常见命令
- PHP正则表达式
- Maven入门到入坑
- 充满思维含量的DP 选美
- 逆序对-ZOJ
- [HDU1466][动态规划DP]计算直线的交点数
- 【修真院“善良”系列之四】怎么识别招聘中的传销公司?
- maven----pom.xml详解