hi im new in yii please help me how to convert this query
SELECT *
FROM students
INNER JOIN borrowedbooks ON student.stud_id = borrowedbooks.stud_id
Please Help
hi im new in yii please help me how to convert this query
SELECT *
FROM students
INNER JOIN borrowedbooks ON student.stud_id = borrowedbooks.stud_id
Please Help
it will help you
http://www.yiiframework.com/doc/api/1.1/CDbCommand
http://www.yiiframework.com/doc/api/1.1/CDbCommand#setJoin-detail
try this
$criteria = new CDbCriteria;
$criteria->select = 't.*, tu.* ';
$criteria->join = ' INNER JOIN `borrowedbooks` AS `tu` ON t.stud_id = tu.stud_id';
//$criteria->addCondition("display_name LIKE '%a%' and blocked_by='76'");
$resultSet = students::model()->find($criteria);
print_r($resultSet);
Wow!! Thankyou Very much it Solve my Problem Thankyou
another thing maggie… How can I implement this to dataprovider.
You have a model named (Student) which contain a relations method:
public function relations() {
return array(
'borrowedbooks' => array(self::HAS_MANY, 'Borrowedbook', 'stud_id', 'joinType' => 'INNER JOIN',),
);
}
And in the Borrowedbook model which contain a relations method:
public function relations() {
return array(
'students' => array(self::BELONGS_TO, 'Student', 'id'),
);
}
In the any actions of controller you need that query just write this:
$model = Student::model()->with('borrowedbooks')->finsAll();
So easy. Isn’t It?
$arrayDataProvider = new CArrayDataProvider($resultSet, array('id' => 'id',
'pagination' => array('pageSize' => 10),
));