我想将data
$form
提取到$to
变量,该变量已存储在其中。所以我基本上想要获取data date wise
。
这是我的代码:
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->condition .= 't.entrydate';
}
$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);
我想在
$criteria->condition .='????';中写条件 在这种情况下应该写什么代码。
答案 0 :(得分:1)
像这样使用MySQL between
: -
$f=$_POST['from'];
$t=$_POST['to']
$criteria->condition .= 't.entrydate BETWEEN $f and $t';
答案 1 :(得分:1)
您可以使用addCondition
,例如:
if ($from != '' && $to != '') {
$criteria->addCondition('t.entrydate >= :startDate AND t.entrydate <= :endDate');
$criteria->params = array(':startDate' => $from, ':endDate' => $to);
}
或使用addBetweenCondition
:
if ($from != '' && $to != '') {
$criteria->addBetweenCondition("entrydate", $from, $to);
}
答案 2 :(得分:1)
使用addBetweenCondition:
if ($from != '' && $to != '') {
$criteria->addBetweenCondition("entrydate", $from, $to);
}