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 
1La Rochelle GiftsNantes118200$0.00
2Baane Mini ImportsStavern81700$0.00
3Mini Gifts Distributors Ltd.San Rafael210500$0.00
4Zbyszek Zbyszek PiestrzeniewiczWarszawa1230$0.00
5Blauer See Auto, Co.Frankfurt59700$0.00
6Mini Wheels Co.San Francisco64600$0.00
7Land of Toys Inc.NYC114900$0.00
8Euro+ Shopping ChannelMadrid227600$0.00
9Volvo Model Replicas, CoLuleå53100$0.00
10Danish Wholesale ImportsKobenhavn83400154.15$-83,245.85
Σ  8045530.126362085.880000001$-628,014.24 
Search