yii if condition within query builder -
class retailjob extends cformmodel { public function getreatilproducts() { $condition=false; $user = yii::app()->db->createcommand() ->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id') ->from('tbl_retailjob') ->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id') ->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id') ->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7)) ->queryall(); return $user; } }
this model file want achieve if $condition truethen condition should avoide , if false should included
can achieve this
public function getreatilproducts() { $condition=true; $user = yii::app()->db->createcommand() ->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id') ->from('tbl_retailjob') ->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id') ->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id') if ($condition !=true) { ->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7)) } ->queryall(); return $user; } }
try this:
public function getreatilproducts() { $condition=true; $command = yii::app()->db->createcommand() ->select('tbl_retailjob.retailjobmaster_id, tbl_retailjob.joborderflag, tbl_retailjoborder.retailjob_id, tbl_retailjoborder.retailjobsub_id, tbl_retailjoborder.filename,tbl_retailpostpressjoborder.retailpostpressjo_id,tbl_retailpostpressjoborder.retailjobsub_id,tbl_retailpostpressjoborder.retailpostpresssub_id') ->from('tbl_retailjob') ->join('tbl_retailjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailjoborder.retailjobmaster_id') ->join('tbl_retailpostpressjoborder', 'tbl_retailjob.retailjobmaster_id=tbl_retailpostpressjoborder.retailjobmaster_id'); if ($condition !=true) { $command->where('tbl_retailjob.retailjobmaster_id=:id', array(':id' => 7)); } $user = $command->queryall(); return $user; }
Comments
Post a Comment