mysql - 改变查询结果

标签 mysql yii

无论如何都可以更改查询的结果,我的数据库表中有几列带有 1 和 0 值,但是 1 和 0 都有含义,比方说 1=可以跳转 0=不跳转,

我使用下面的代码进行查询,它会给我返回带有 0 和 1 的列,无论如何都很容易将此值更改为可以跳转/不跳转,我猜想像过滤器或其他东西....

public function search()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('result',$this->result,true);
        $criteria->compare('p_city',$this->p_city,true);
        $criteria->compare('p_state',$this->p_state,true);
        $criteria->compare('d_city',$this->d_city,true);
        $criteria->compare('d_state',$this->d_state,true);      
        $criteria->compare('type',$this->type,true);
        $criteria->compare('date_search',$this->date_search,true);
        $criteria->compare('date_shipped',$this->date_shipped,true);
        $criteria->compare('driveable',$this->driveable,true);
        $criteria->compare('enclosing',$this->enclosing,true);
        $criteria->compare('type_service',$this->type_service,true);
                $criteria->order='date_search desc';
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

最佳答案

您可以通过在模型中使用 afterFind 函数来完成此操作:

public function afterFind() {
    $this->driveable == '1' ? 'Yes' : 'No';
}

关于mysql - 改变查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950551/

相关文章:

php - SQL : Command Create Virtual Row If Not Exist

php - Yii Framework testing with PHPUnit and Selenium 错误/警告

php - 通过 composer 安装 Yii2 失败

yii - 创建新迁移时未定义 CConsoleApplication.defaultController

postgresql - 无法使用 Yii 连接 PostgreSQL

php - 如何显示 MySQL 数据库中数据的提取次数?

mysql - 我想要一个触发器从 MySQL 中的 2 个表中删除

php - 在 CGridView 的 htmlOptions 中添加表达式

mysql - 如何使用promise在node js中对多个mysql查询进行事务操作?

php - 使用 PHP 身份验证密码保护整个目录