Php Laravel 5.1-mysql orderby count distinct的最高值
我的主要目的是展示我的畅销产品 我的表名是带有列(id、购物车id、产品id等)的订单项目 控制器:Php Laravel 5.1-mysql orderby count distinct的最高值,php,mysql,laravel,Php,Mysql,Laravel,我的主要目的是展示我的畅销产品 我的表名是带有列(id、购物车id、产品id等)的订单项目 控制器: $orderitems = DB::table('order_items') ->select('product_id')->get(); Html: 但它失败了,并发出了一条信息: Fatal error: Call to undefined function App\Http\Controllers\distict() 下面是如何使用distinct方法(和o
$orderitems = DB::table('order_items')
->select('product_id')->get();
Html:
但它失败了,并发出了一条信息:
Fatal error: Call to undefined function App\Http\Controllers\distict()
下面是如何使用
distinct
方法(和orderBy
):
我有一个错误:为foreach()提供的参数无效(视图:C:\wamp64\www\test3\resources\views\master\master.blade.php)我的错误。。。我只是重新修改了我的答案。我忘记了NT
->get()
另一个错误:致命错误:调用数组上的成员函数pulk()。是否可以:dd($orderitems)它给我数组3:->
$orderitems = DB::table('order_items')
->select('product_id')->orderBy(distict(count('product_id')));
Fatal error: Call to undefined function App\Http\Controllers\distict()
$orderitems = DB::table(DB::raw('(SELECT product_id, COUNT(*) as product_count FROM order_items GROUP BY product_id) AS subquery'))
->select('product_id')
->orderBy('product_count')
->get();