Changes
Title
unchanged
Use CGridview to sort and filter CSqlDataProvider - when used with UNRELATED tables (or complex queries)
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
CSqlDataProvider unrelated
Content
changed
[...]
// If gv_hospitals was received from CGridview, then
// filter records with a WHERE clause
if( ($this->gv_hospitals !== null) &&
($this->gv_hospitals !== ''))
{
// The LIKE operator in the WHERE clause acts the same
// as this line in Relational Query:$criteria = new CDbCriteria;
// $criteria->compare('hosp_name',$this->gv_hospitals,
true);
$
sql="
SELECT
condition = $criteria->condition;
$params = $criteria->params;
unset($criteria);
$sql = Yii::app()->db->createCommand()
->select("
concat(tbl_hosp.hosp_id, tbl_dept.dept_id) AS compkey,
tbl_hosp.hosp_id
AS hosp_id,
tbl_hosp.hosp_name
AS hosp_name,
tbl_dept.dept_name
AS dept_name
FROM
")
->from("tbl_hosp, tbl_dept
WHERE
tbl_hosp.hosp_name LIKE '%" . $this->gv_hospitals . "%'";
}
else
{
$sql="
SELECT
")
->where($condition, $params);
}
else
{
$sql = Yii::app()->db->createCommand()
->select("
concat(tbl_hosp.hosp_id, tbl_dept.dept_id) AS compkey,
tbl_hosp.hosp_id
AS hosp_id,
tbl_hosp.hosp_name
AS hosp_name,
tbl_dept.dept_name
AS dept_name
FROM
")
->from("tbl_hosp, tbl_dept"
);
}
return new CSqlDataProvider($sql, array(
// Use the composite key to keep the (hidden) key values of your[...]