這個是我在model檔案裡面寫的一個方法。我想將一張表(t) 和 另一張表 c 做外串連(left join)。
public function pagination($limit, $condition, $order){ $criteria = new CDbCriteria(); $criteria->alias = 't'; $criteria->order = $order; $criteria->select = 't.id, c.value'; $criteria->addCondition($condition); $criteria->join = 'left join lp_site_conf as c on t.type=c.id'; $result['listInfo'] = YiiData($this->findAll($criteria)); $result['pageCount'] = $pages->getPageCount(); }
但是 現在查出來的資料是這樣的
array(10) { [0] => array(9) { ["id"] => string(2) "10" ["name"] => NULL ["type"] => NULL ["createuid"] => NULL ["createtime"] => NULL ["modifytime"] => NULL ["description1"] => NULL ["description2"] => NULL ["status"] => NULL } [1] => array(9) { ["id"] => string(1) "9" ["name"] => NULL ["type"] => NULL ["createuid"] => NULL ["createtime"] => NULL ["modifytime"] => NULL ["description1"] => NULL ["description2"] => NULL ["status"] => NULL }
這些欄位都是t表中的,根本沒有leftjoin的表的欄位,這是什麼原因?
回複內容:
這個是我在model檔案裡面寫的一個方法。我想將一張表(t) 和 另一張表 c 做外串連(left join)。
public function pagination($limit, $condition, $order){ $criteria = new CDbCriteria(); $criteria->alias = 't'; $criteria->order = $order; $criteria->select = 't.id, c.value'; $criteria->addCondition($condition); $criteria->join = 'left join lp_site_conf as c on t.type=c.id'; $result['listInfo'] = YiiData($this->findAll($criteria)); $result['pageCount'] = $pages->getPageCount(); }
但是 現在查出來的資料是這樣的
array(10) { [0] => array(9) { ["id"] => string(2) "10" ["name"] => NULL ["type"] => NULL ["createuid"] => NULL ["createtime"] => NULL ["modifytime"] => NULL ["description1"] => NULL ["description2"] => NULL ["status"] => NULL } [1] => array(9) { ["id"] => string(1) "9" ["name"] => NULL ["type"] => NULL ["createuid"] => NULL ["createtime"] => NULL ["modifytime"] => NULL ["description1"] => NULL ["description2"] => NULL ["status"] => NULL }
這些欄位都是t表中的,根本沒有leftjoin的表的欄位,這是什麼原因?
我遇到了和你一樣的問題,你是怎麼解決的呢?