dongzhao3040 2011-05-16 13:10
浏览 42
已采纳

Yii SQL到CActiveDataProvider

I need help from Yii experts, I have a SQL query

SELECT p.name , p.price FROM products as p, prod_cat as pc WHERE pc.id_pr  =  p.id_pr AND pc.id_cat in (SELECT id_cat FROM prod_cat where id_pr=<myid>)

I need to convert this to CActiveDataProvider in Yii. something like this

            $dataProvider2=new CActiveDataProvider('Products',array(
                        'criteria' => array(
                             ...                                      
                        ),

                ));

I have 3 Tables : Products, Categories and Prod_cat (connection between two others). I need to find others products from the same category of item that i provide ().

  • 写回答

2条回答 默认 最新

  • duanbei8904 2011-05-16 18:01
    关注

    I would create a view in your database (using that query). Then make a model in Yii based on that view. Creating an activedataprovider will then be easy.

    http://en.wikipedia.org/wiki/View_(database)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 如果update 一个列名为参数的value
  • ¥15 基于51单片机的水位检测系统设计中LCD1602一直不显示
  • ¥15 OCS2安装出现问题,请大家给点意见
  • ¥15 ros小车启动launch文件报错
  • ¥15 vs2015到期想登陆但是登陆不上
  • ¥15 IPQ5018制作烧录固件,boot运行失败(操作系统-linux)(相关搜索:操作系统)(相关搜索:操作系统)
  • ¥20 icefall在librispeech基础上加入个人数据集
  • ¥30 keepalive高可用故障运维配置询问
  • ¥15 求帮助!国家电网内网u盘突然识别不出来了。
  • ¥15 matlab语音变速变调同时实现