DEMO SITE v1.7.15

Subselect and sum row Bootstrap 4.5 theme

Subselect() will create a new column with some value from other (or current) table. You can use any columns from current tables as parameters. Subselect will be called for each row

HIDE CODE
<?php
	$xcrud = Xcrud::get_instance();
    $xcrud->table('customers');
    $xcrud->columns('customerName,city,creditLimit,Paid,Profit'); // specify only some columns
    $xcrud->subselect('Paid','SELECT SUM(amount) FROM payments WHERE customerNumber = {customerNumber}'); // other table
    $xcrud->subselect('Profit','{Paid}-{creditLimit}'); // current table
    $xcrud->sum('creditLimit,Paid,Profit'); // sum row(), receives data from full table (ignores pagination)
    $xcrud->change_type('Profit','price','0',array('prefix'=>'$')); // number format
    echo $xcrud->render();
?>

Customers

#CustomernameCityCreditlimitPaidProfit 
1Mini Gifts Distributors Ltd.San Rafael210500$0.00
2Zbyszek Zbyszek PiestrzeniewiczWarszawa1230$0.00
3Blauer See Auto, Co.Frankfurt59700$0.00
4Mini Wheels Co.San Francisco64600$0.00
5Land of Toys Inc.NYC11490035321.97$-79,578.03
6s2401213.95$0.00
7Volvo Model Replicas, CoLuleå5310043680.65$-9,419.35
8Danish Wholesale ImportsKobenhavn8340086881.64$3,481.64
9Saveley & Henriot, Co.Lyon123900130305.9$6,405.90
10Dragon Souveniers, Ltd.Singapore103800156251.03$52,451.03
Σ  7618030.129181943.980000004$-501,270.09 
Search