【问题标题】:how to use "find_in_set" in cakephp find method如何在 cakephp 查找方法中使用“find_in_set”
【发布时间】:2012-03-03 09:43:01
【问题描述】:

我有一个表,其中另一个表的逗号分隔 id 我想在 cakephp 中以适当的形式使用以下查询和查找功能

"select * from special_offers where find_in_set('".$storeId."', stores) and user_id = '". $userId ."'";

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    这样使用

    $data = $this->SpecialOffer->find('all',array('conditions' => array('SpecialOffer.user_id' => $userId ,'FIND_IN_SET(\''. $storeId .'\',SpecialOffer.stores1)')));
    

    希望对你有帮助

    【讨论】:

    • 我认为使用数组语法会更简洁(用于自动转义等):FIND_IN_SET(?, SpecialOffer.stores1)' => array($storeId),
    • 是的,我们可以使用数组,但如果我们有 id 数组并使用数据库上的单个 id 对其进行数学运算,我们可以使用数组,但我有一个来自 url 的 id 和数据库中逗号分隔的 id为什么我需要这个(“find_in_set”)
    • @ShivomkaraChaturvedi,如何使查询动态化,意味着我想使用逗号分隔的 id,(在使用 $storeId(variable) 获取多条记录时效率不高。
    猜你喜欢
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多