首先status类型为enum(‘0’, ‘1’)

        $meals = Db::name('vip_meal')
            ->where(array('vip_id'=>$vipId,'status'=>1))
            ->order('price')
            ->select();
对应sql语句
SELECT * FROM `sand_vip_meal` WHERE `vip_id` = 1 AND `status` = '1' ORDER BY `price`
可以获取数据:
[{"id":5,"vip_id":1,"price":"500.00","status":"1","times":6},{"id":1,"vip_id":1,"price":"800.00","status":"1","times":12},{"id":3,"vip_id":1,"price":"1000.00","status":"1","times":24}]

$meals = Db::name('vip_meal')
            ->where(array('vip_id'=>$vipId,'status'=>'1'))
            ->order('price')
            ->select();
对应sql语句
SELECT * FROM `sand_vip_meal` WHERE `vip_id` = 1 AND `status` = '1' ORDER BY `price`
也可以正常查询数据

坑来了~~~

              $meals = Db::name('vip_meal')
                    ->alias('m')
                    ->where(array('m.vip_id'=>$vipId,'m.status'=>1))
                    ->order('m.price')
                    ->select();
对应sql语句
SELECT * FROM `sand_vip_meal` `m` WHERE `m`.`vip_id` = '1' AND `m`.`status` = 1 ORDER BY `m`.`price`
竟然找不到数据~

              $meals = Db::name('vip_meal')
                    ->alias('m')
                    ->where(array('m.vip_id'=>$vipId,'m.status'=>'1'))
                    ->order('m.price')
                    ->select();
SELECT * FROM `sand_vip_meal` `m` WHERE `m`.`vip_id` = '1' AND `m`.`status` = '1' ORDER BY `m`.`price`
正常输出

        $meals = Db::name('vip_meal')
            ->alias('m')
            ->join('vip v','v.id = m.vip_id')
            ->where(array('m.vip_id'=>$vipId,'m.status'=>'1'))
            ->order('m.price')
            ->select();
对应sql语句
SELECT * FROM `sand_vip_meal` `m` INNER JOIN `sand_vip` `v` ON `v`.`id`=`m`.`vip_id` WHERE `m`.`vip_id` = '1' AND `m`.`status` = '1' ORDER BY `m`.`price`

必须将status字段设置为’m.status’=>’1′,因为字段类型为enum(‘0’, ‘1’)

发表评论

邮箱地址不会被公开。 必填项已用*标注