【问题标题】:Get the first 20 records from the table in magento从magento中的表中获取前20条记录
【发布时间】:2013-12-16 11:24:44
【问题描述】:

我遇到了无法解决的问题。部分原因是我无法用正确的术语来解释它。我是新手,很抱歉这个笨拙的问题。

您可以在下面看到我的目标概览。

我正在使用 Magento CE 1.7.0.2

$_PCollection = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')
                    ->setVisibility(array(2,3,4))                   
                    ->setOrder('created_at', 'desc');

我确实喜欢它的工作正常,但我只想要前 20 个产品。

那我该怎么做呢?

有什么想法吗?

【问题讨论】:

  • 我想从数据库中获取前 20 条记录。

标签: php magento


【解决方案1】:

您可能需要使用->setPageSize(20);

$_PCollection = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->setVisibility(array(2,3,4))                   
                ->setOrder('created_at', 'desc')
                ->setPageSize(20)
                >setCurPage(1);

或者你也可以使用它

$_PCollection->getSelect()->limit(20);

【讨论】:

    【解决方案2】:

    你可以使用,

     ->setPage(1, 20) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-01
      相关资源
      最近更新 更多