Answer the question
In order to leave comments, you need to log in
How to sum up the total amount of all payments from the database in yii and display it on the screen?
Good afternoon, the question arose, how to add up the total amount of all payments from the database in yii and display it on the screen?
UserPayout.php:
class UserPayout extends CActiveRecord
{
public
$id,
$user_id,
$system,
$currency,
$purse,
$sum,
$create_time,
$status;
public function tableName()
{
return '{{users_payouts}}';
}
public function rules()
{
return array(
// create
array('sum, system, purse, currency', 'required', 'on' => self::SCENARIO_CREATE),
array('sum', 'numerical', 'integerOnly'=>true, 'on' => self::SCENARIO_CREATE, 'message'=>'Сумма должна быть целым числом.'),
array('sum', 'checkSumValue', 'on' => self::SCENARIO_CREATE),
array('currency', 'isCurrencyValid', 'on' => self::SCENARIO_CREATE),
array('purse', 'isPurseValid', 'on' => self::SCENARIO_CREATE),
// update
array('id', 'required', 'on' => self::SCENARIO_UPDATE),
// system & currency update
array('currency', 'safe', 'on' => self::SCENARIO_SYSTEM_UPDATE),
array('system', 'safe', 'on' => self::SCENARIO_CURRENCY_UPDATE),
// search
array('id, username_search, system, currency, purse, sum, data, create_time, status, from_date, to_date', 'safe', 'on'=>self::SCENARIO_SEARCH),
// rules
array('id', 'exist', 'attributeName'=>'id'),
array('system', 'in', 'range' => $this->getSystemValidValues()),
array('currency', 'in', 'range' => ICurrency::getValidValues()),
array('sum', 'length', 'min'=>1, 'max'=>8),
array('purse', 'filter', 'filter' => array($obj=new CHtmlPurifier(),'purify')),
);
}
}
<h2>Всего выплат в рублях: <?= (new UserPayout)->find('sum')->count()?> Р</h2>
Answer the question
In order to leave comments, you need to log in
$query = (new \yii\db\Query())->from('users_payouts');
// вот это будет сумма
$sum = $query->sum('sum');
echo $sum;
the usual wizard, the network is full of examples:
https://yandex.ru/search/?text=wizard%20jquery&cli
...
www.jquery-steps.com/Examples
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question