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

标签 mysql join search yii yii1.x

我有两个相关表,我必须通过连接查询显示来自两个表的数据。 我有这个 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/

相关文章:

mysql - sql 不喜欢 "%term%"不工作

python - 当给定 dict1 key2 时查找 dict1 key1 的值?

zend-framework - 您使用什么搜索表单?获取查询或路由参数?

mysql - 未找到特定记录时插入

php - 为所有用户更新的共享 HTML 页面

sql - 我可以使用自定义类型字段加入吗?

html - 如何添加功能 Bootstrap 搜索栏

MySQL Join、Select、多个条件

4个表之间的Mysql内部连接

sql - 具有 5 个表的复杂 SQL 连接