gpt4 book ai didi

mysql - 选择在 Yii CDbCriteria 中不起作用

转载 作者:行者123 更新时间:2023-11-30 21:43:13 26 4
gpt4 key购买 nike

我有两个相关表,我必须通过连接查询显示来自两个表的数据。我有这个 GridView,当我必须进行搜索时它正在“工作”,这意味着如果我必须从连接表中搜索一个字段,它会工作并显示正确的结果,但我我无法显示两个表中的所有列。

这里是错误:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'pratiche'. The SQL statement executed was: SELECT pratiche.* FROM pratiche t LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10

如您所见,pratiche 后面有t,因此查询失败。有什么问题?

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,
));
}

最佳答案

解决了!设置条件的错误方法:

$criteria->select=array('id_pratiche','data_creazione','stato_pratica','nome','cognome');

关于mysql - 选择在 Yii CDbCriteria 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50657099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com