我有两个相关的表,我必须通过连接查询显示数据。
当我必须进行搜索时,我有GridView
“工作”,所以这意味着如果我必须从连接表中搜索一个字段,它可以工作并显示正确的结果,但我不能显示两个表中的所有列。
这是错误:
CDbCommand无法执行SQL语句:SQLSTATE [42S02]:Base 未找到表格或视图:1051未知表格'pratiche'。 SQL 执行的语句是:SELECT pratiche。* FROM
pratiche
t
LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10
正如您在t
之后看到pratiche
,因此查询失败。
有什么问题?
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->select = "pratiche.*,clienti.*";
$criteria->join='LEFT JOIN clienti ON id_cliente = clienti.id';
$criteria->compare('id_pratiche',$this->id_pratiche,true);
//this is the fild that should be shown(from the joined table)
$criteria->compare('codice_fiscale',$this->codice_fiscale,true);
$criteria->select = "pratiche.*";
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
答案 0 :(得分:0)
解决了! 设置标准的错误方法:
$criteria->select=array('id_pratiche','data_creazione','stato_pratica','nome','cognome');