【问题标题】:how to retrieve all product from the db using an id's list?如何使用 id 列表从数据库中检索所有产品?
【发布时间】:2010-10-21 08:07:43
【问题描述】:

我有一系列产品 ID:

$product_ids = array(10,14,15,...);

我想使用 Cakephp 的 ORM 在数据库中找到所有相应的产品。我正在使用 Mysql,所以查询类似于:

SELECT *
FROM products
WHERE id
IN ( 10, 14, 15,... )

我可以使用query() 函数,但这似乎是解决这个问题的一种草率方法。也许我可以使用find() 函数,但我不知道如何......有什么想法吗?

【问题讨论】:

    标签: php orm cakephp


    【解决方案1】:

    你试过了吗:

    $this->Product->find('all', array('conditions' => array('Product.id' => $product_ids)));
    

    ?

    【讨论】:

    • 哇...它有效 =D 我只是假设它不起作用。我想我低估了蛋糕的力量。谢谢!
    猜你喜欢
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多