我不想获取空数据

时间:2015-10-29 06:49:49

标签: php mysql yii

我不想获取空值。这是我的代码,它是获取空值的数据。

        if ($_POST['data'] == 'paymentanalyticdata') {


            $criteria = new CDbCriteria;
            $criteria->join = 'LEFT OUTER JOIN payment_integration AS PI ON PI.name = t.payment_method AND PI.store_id=' . Yii::app()->session['store_id'];
            $criteria->select = 'PI.title as payment_method,sum(t.total) as total';
            $criteria->group = 'PI.title';
            $criteria->condition = 't.store_id=\'' . Yii::app()->session['store_id'] . '\'';

            $from = isset($_POST['from']) ? $_POST['from'] : "";
            $to = isset($_POST['to']) ? $_POST['to'] : "";

            if ($from != "" && $to != "") 
            {

                $criteria->addBetweenCondition("t.date_added", $from, $to);
            }
            $list = Order::model()->findAll($criteria);

            $categorylist = [];
            foreach ($list as $row) {
                $categorylist[] = array('PI' => $row->payment_method, 'total' => $row->total);
            }

            $seocount['paymentanalyticdata'] = $categorylist;
            echo json_encode($seocount);
        }

Out Put是:

 paymentanalyticdata: [{PI: null, total: "1188947.00"}, {PI: "2checkout",  total: "48988.95"},…]
 0: {PI: null, total: "1188947.00"}
 1: {PI: "2checkout", total: "48988.95"}
 2: {PI: "authorize .net", total: "225047.90"}
 3: {PI: "braintree ", total: "42390.00"}
 4: {PI: "Cash On Delivery", total: "5225819.65"}
 5: {PI: "ccavenue ", total: "133968.95"}

我不想获取null为0:{PI:null,total:" 1188947.00"}

2 个答案:

答案 0 :(得分:0)

$criteria->join = 'LEFT OUTER JOIN payment_integration AS PI ON PI.name = t.payment_method AND PI.title IS NOT NULL AND PI.store_id=' . Yii::app()->session['store_id'];

PI.title IS NOT NULL。我想你错过了这个。

希望这有帮助

答案 1 :(得分:0)

在脚本方面,

    foreach ($list as $row)
    {
      if(($row->payment_method != null) && ($row->payment_method != ''))
      {
        $categorylist[] = array('PI' => $row->payment_method, 'total' => $row->total);
      }
    }

在查询方面,

$criteria->join = 'LEFT OUTER JOIN payment_integration AS PI ON PI.name = t.payment_method AND (PI.title IS NOT NULL AND PI.title != '') AND PI.store_id=' . Yii::app()->session['store_id'];