![](/img/trans.png)
[英]PHP/MySQL: How to compare the sum of certain fields on a query to a number?
[英]How to sum two mysql fields in php
我是PHP的初學者,我嘗試使這項工作。 我買了一個准備好的腳本,嘗試改變和學習。 我有這樣的一排
{!! $profile->likes()->where('like_type', 1)->count() !!}
該代碼在數據庫中將所有“1”加起來並顯示結果。 我想在這個結果中添加“+”另一個。 該字段稱為like_plus。
我試過這個
{!! $profile->likes()->where('like_type', 1->count() + 'like_plus') !!}
Like_plus字段包含1-1000的數字,其中Like_type包含數字1或2。
我希望代碼首先進行計數,然后在DB中進行+ Like_plus數字。
根據我的理解,你需要總結like_type
的計數是1到like_pluse
值到相關的like_type
你可以這樣做,
{!! $profile->likes()->where('like_type', 1)->count() + $profile->likes()->where('like_type', 1)->like_plus !!}
希望這可以幫助。
試試這個: {!! $ profile-> likes() - > where('like_type',1) - > count()+ $ profile-> likes() - > where('like_plus',1) - > count()!!}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.