Find us on facebook

Jul 29, 2014

FindAll() in Yii

$sql="SELECT image from table_type_images where table_type_id =".$Table->shape." AND chairs = ".$Table->chairs;
$TableTypeImage = TableTypeImages::model()->findBySql($sql);

$Table=Table::model()->findByPK($table_id);

$models = Vehicle::model()->findAll( array('order' => 'vehicle_no'));

$AuthitemDes = Authitem::model() -> findAll('type = 0 AND description IS NOT NULL');
FindAll with Where clause = condition
MainMenu::model() -> findAll(array("condition"=>"res_id =  $res_id","order"=>"name"));​

FindAll with Where clause Like condition
$Staff= CHtml::listData(AuthAssignment::model() -> findAll('itemname LIKE :Staff',array(':Staff' => "%Staff%")), 'userid', 'userid');

Joining Two tables
$criteria=new CDbCriteria;$criteria->select = 't.userid,users.username';$criteria -> join = 'JOIN  users on userid= users.id';$criteria->condition = 'itemname LIKE :Staff OR itemname LIKE :Admin OR itemname LIKE :Cashier'; $criteria->params    = array(':Staff'=>'%Staff%',':Admin'=>'%Admin%',':Cashier'=>'%Cashier%'); $criteria->order = 'username DESC,userid DESC';$Staff = AuthAssignment::model()->findAll($criteria);$StaffList= CHtml::listData($Staff, 'userid', 'username');​echo $form->dropDownList($model,'emp_id',$StaffList);​



$res_id = $_POST['res_id'];

$criteria=new CDbCriteria;
$criteria->select = 'Distinct t.id,t.name';
$criteria -> join = 'JOIN  menu on t.id= menu.main_menu';
$criteria->condition = 't.res_id =:res_id'; 
$criteria->params    = array(':res_id'=>$res_id); 



$mainMenu = MainMenu::model() -> findAll($criteria);

No comments:

Post a Comment