laravel在控制器中划分并在blade中显示

nlejzf6q  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(292)

我的剧本写得很好,但演得不对。在这个代码的例子中,我有5个人和大多数人有%的伤害。

$user->bestaimers = DB::table('csstats AS cs')
>leftJoin('users AS u', DB::raw('BINARY u.steam_id'), '=', DB::raw('BINARY cs.steamid'))
->select("cs.*", "u.*")
->orderBy('cs.h_1', 'desc')->orderBy('hits', 'desc')
->take(5)
->get('');

我的观点是:

@foreach ($user->bestaimers as $bestaimer)
<?php echo number_format($bestaimer->h_1 / $bestaimer->hits * 100,2); ?>%
    @endforeach

但这是第一个拥有最多命中率的球员。我需要按$bestaimer->h\u 1/$bestaimer->hits*100,2订购
有什么帮助吗?

67up9zun

67up9zun1#

也许您应该尝试在sql中选择$bestaimer->h_1/$bestaimer->hits*100,2,然后按此值排序?
像这样: SELECT cs.*, u.*, (ROUND(cs.h_1/hits*100,2)) as val FROM csstats as cs LEFT JOIN users as u ON u.steam_id = cs.steamid ORDER BY val DESC LIMIT 5

相关问题