简体   繁体   English

如何在php中总结两个mysql字段

[英]How to sum two mysql fields in php

Im beginner in PHP and I try make this work. 我是PHP的初学者,我尝试使这项工作。 I bought a ready script and trying change and learn. 我买了一个准备好的脚本,尝试改变和学习。 I have a row like this 我有这样的一排

{!! $profile->likes()->where('like_type', 1)->count() !!}

That code sum all "1" in database and show the result. 该代码在数据库中将所有“1”加起来并显示结果。 I want just add "+" another filed to this result also. 我想在这个结果中添加“+”另一个。 the filed is called like_plus. 该字段称为like_plus。

I tried this 我试过这个

{!! $profile->likes()->where('like_type', 1->count() + 'like_plus') !!}

The Like_plus field contain number from 1-1000 where Like_type contains the number 1 or 2. Like_plus字段包含1-1000的数字,其中Like_type包含数字1或2。

I want the code do the count first and then + Like_plus numbers in DB. 我希望代码首先进行计数,然后在DB中进行+ Like_plus数字。

From what I understand you need to sum up the count of the like_type is 1 to like_pluse value to that relevant like_type 根据我的理解,你需要总结like_type的计数是1到like_pluse值到相关的like_type

you can do it like this, 你可以这样做,

{!! $profile->likes()->where('like_type', 1)->count() + $profile->likes()->where('like_type', 1)->like_plus !!}

Hope this helps. 希望这可以帮助。

Try this: {!! 试试这个: {!! $profile->likes()->where('like_type', 1)->count() + $profile->likes()->where('like_plus', 1)->count() !!} $ profile-> likes() - > where('like_type',1) - > count()+ $ profile-> likes() - > where('like_plus',1) - > count()!!}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM