我想从订单表中计算cashondelivery,paypal,payu,ccavenue的总数。
在订购表中有payment_method列。 在该列中,有多种付款方式。
我想计算一下通过cashondelivery,paypal,payu等付款多少....(使用yii框架时)。
$list = Order::model()->findAll(payment_method=cashondelivery);
var_dump($list);
exit;
我如何做到这一点,以便我的输出如下
cashondelivery = 50
paypal = 25
payu = 35
答案 0 :(得分:0)
试试这个:
$CodCount = Order::model()->countByAttributes(array(
'payment_method'=>'cashondelivery'
));
echo $CodCount; //returns number of cashondelivery
....//similarly for other payment types
或,
$CodCount = Order::model()->count("payment_method=:val", array("val" => "cashondelivery"));
echo $CodCount; //returns number of cashondelivery
....//similarly for other payment types
,或者
$dbCommand = Yii::app()->db->createCommand("
SELECT payment_method,COUNT(*) as tot FROM `order` GROUP BY `payment_method`
");
$data = $dbCommand->queryAll();
foreach($data AS $val) {
echo "Payment Method: ".$val["payment_method"]." total: ".$val["tot"]."<br/>";
}
输出
Payment Mode: cashondelivery total: 50
Payment Mode: paypal total: 25
Payment Mode: payu total: 35