Reputation: 101
I want to fetch data
$form
to $to
variable which has date stored in it. so basicaly I want to fetch the data date wise
.
Here is my code:
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);
I want to write condition in
$criteria->condition .='????';What code should be write in this condition.
Upvotes: 0
Views: 594
Reputation: 101
using addBetweenCondition:
if ($from != '' && $to != '') {
$criteria->addBetweenCondition("entrydate", $from, $to);
}
Upvotes: 0
Reputation: 2001
You could use addCondition
, something like:
if ($from != '' && $to != '') {
$criteria->addCondition('t.entrydate >= :startDate AND t.entrydate <= :endDate');
$criteria->params = array(':startDate' => $from, ':endDate' => $to);
}
or, by using addBetweenCondition
:
if ($from != '' && $to != '') {
$criteria->addBetweenCondition("entrydate", $from, $to);
}
Upvotes: 1
Reputation: 6661
use MySQL between
like that :-
$f=$_POST['from'];
$t=$_POST['to']
$criteria->condition .= 't.entrydate BETWEEN $f and $t';
Upvotes: 1