d135ks
(Linda Anim)
August 1, 2011, 1:43am
1
i made a function like this :
public function actionAdmin()
{
$date = explode("a",$_GET['date']);
$media = $_GET['media'];
$adv = $_GET['adv'];
$prod = $_GET['prod'];
$group = $_GET['group'];
$criteria = new CDbCriteria;
$criteria->addCondition('start_periode >= :to AND stop_periode <= :from');
$criteria->params=array(
':to'=>$date[0]." 00:00:00",
':from'=>$date[1]." 23:59:59",
);
);
it’s work but when i put another code it made error
the code i add is
if($media != null)
$criteria->addCondition('id_media_seller = :prm');
$criteria->params=array(
':prm'=>$media,
did i miss something?
the error was CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The SQL statement executed was: SELECT COUNT(*) FROM tbl_batch
t
WHERE (start_periode >= :to AND stop_periode <= :from) AND (id_media_seller = :prm)
ivica
(Ivica Nedeljkovic)
August 1, 2011, 4:05am
2
You missed curvy brackets:
if($media != null){
$criteria->addCondition('id_media_seller = :prm');
$criteria->params=array(
':prm'=>$media,);
}
ririn
(Ririn Uktarini)
August 1, 2011, 5:50am
4
if you want to get the value. try $_GET[‘Model’][‘attribute’] is same with $model->attribute if we get from database
. i hope this can help your problem…
d135ks
(Linda Anim)
August 1, 2011, 6:05am
5
thanks but it still error
softark
(Softark)
August 1, 2011, 10:12am
6
public function actionAdmin()
{
...
$criteria = new CDbCriteria;
$criteria->addCondition('start_periode >= :to AND stop_periode <= :from');
$criteria->params=array(
':to'=>$date[0]." 00:00:00",
':from'=>$date[1]." 23:59:59",
);
...
if($media != null){
$criteria->addCondition('id_media_seller = :prm');
$criteria->params=array(
':prm'=>$media,
);
}
...
In the above, the 2nd “$criteria->params=…” will overwrite the 1st one, and ‘:to’ and ‘:from’ will be lost and only ‘:prm’ will remain in $criteria->params.
So, try the following:
public function actionAdmin()
{
...
if($media != null){
$criteria->addCondition('id_media_seller = :prm');
- $criteria->params=array(
- ':prm'=>$media,
- );
+ $criteria->params[':prm']=$media;
}
...
[EDIT]
Sorry.
The code should be:
public function actionAdmin()
{
...
if($media != null){
$criteria->addCondition('id_media_seller = :prm');
$criteria->params += array(':prm'=>$media);
}
...
d135ks
(Linda Anim)
August 2, 2011, 1:53am
7
softark:
In the above, the 2nd “$criteria->params=…” will overwrite the 1st one, and ‘:to’ and ‘:from’ will be lost and only ‘:prm’ will remain in $criteria->params.
So, try the following:
public function actionAdmin()
{
...
if($media != null){
$criteria->addCondition('id_media_seller = :prm');
- $criteria->params=array(
- ':prm'=>$media,
- );
+ $criteria->params[':prm']=$media;
}
...
sorry, its still not work
d135ks
(Linda Anim)
August 2, 2011, 2:02am
8
i use this code and it’s working now but just for the $media not null, if its null its error
$criteria->addCondition('date >= :to AND date <= :from');
if($media != null)
$criteria->addCondition('id_media_seller = :prm');
$criteria->params=array(
':to'=>$date[0],
':from'=>$date[1],
':prm'=>$media,
);
i try to add this code
if($media != null)
':prm'=>$media,
in $criteria->params=array, but this not working. how to add the if condition in params?
thanks
ririn
(Ririn Uktarini)
August 4, 2011, 1:14am
9
this simple code to make conditions with params
so i make condition where the id from downcatid is $_GET[‘id’]
and i use dataProvider. i hope this help you
public function actionList()
{
$criteria= new CDbCriteria(array(
'condition'=>'active=0 AND downcatid=:downcatid',
'params'=>array(':downcatid'=>$_GET['id']),
));
$dataProvider=new CActiveDataProvider('Down',array(
'criteria'=>$criteria,
));
$this->render('list',array(
'dataProvider'=>$dataProvider,
));
}
d135ks
(Linda Anim)
August 4, 2011, 4:22am
10
this simple code to make conditions with params
so i make condition where the id from downcatid is $_GET[‘id’]
and i use dataProvider. i hope this help you
public function actionList()
{
$criteria= new CDbCriteria(array(
'condition'=>'active=0 AND downcatid=:downcatid',
'params'=>array(':downcatid'=>$_GET['id']),
));
$dataProvider=new CActiveDataProvider('Down',array(
'criteria'=>$criteria,
));
$this->render('list',array(
'dataProvider'=>$dataProvider,
));
}
thanks rin for the help, it solved now