douluoyou9876 2014-10-13 03:49
浏览 216
已采纳

YII中的addBetweenCondition

SO I want to find that if value x is exits between the values of 2 columns or not, For that i have run the query in phpmyadmin :

Normal Approch :-

SELECT * FROM `traits_versions` WHERE 16 BETWEEN `trait_value_lower` and `trait_value_upper` and `style_id` = 1 

and it is giving me fine result.But when the same approach i want to find achieve in YII that it is not running and giving the sql error :

YII apprroch :-

    $details = array();
        $criteria = new CDbCriteria();
        $criteria->addCondition('style_id='.$style_id);
        $criteria->addCondition('version='.$version);
$criteria->addBetweenCondition($style_contribution,$this->trait_value_lower,$this->trait_value_upper);
        $trait_details= $this->find($criteria);

When i debug the query in log than it shows in case of yii :

SELECT * FROM `traits_versions` `t` WHERE ((style_id=1) AND (version=1)) AND (16 BETWEEN NULL AND NULL) LIMIT 1

Why it is giving NULL value in query while i'm passing the name of the column in it. So please guide me where i'm going wrong in yii.

  • 写回答

1条回答 默认 最新

  • duanph1978 2017-03-13 23:38
    关注

    Add compare condition like below

    $criteria->compare('trait_value_lower', 16, false, '>');
    $criteria->compare('trait_value_upper',16, false, '<');
    

    instead of between condition

    $criteria->addBetweenCondition($style_contribution,$this->trait_value_lower,$this->trait_value_upper);
    

    because between condition will apply on one column as per Yii doc.

    public static addBetweenCondition(string $column, string $valueStart, string $valueEnd, string $operator='AND')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部