douluoyou9876 2014-10-13 11: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-14 07: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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器