通过rand()查询magento限制+订单 [英] query magento limit + order by rand()

查看:61
本文介绍了通过rand()查询magento限制+订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function getIdModelsSliderJuwels(){
 $collection = Mage::getModel("catalog/product")->getCollection();
 $collection->addAttributeToFilter("attribute_set_id", 27); 
     $collection->addAttributeToSelect('modellijnen'); 
   //  $collection->setRandomOrder();
   //  $collection->getSelect()->limit( 5 ); 
 return $collection; 
}

你好,

我想知道如何为在Magento中运行的查询设置限制,因为 $collection->getSelect()->limit( 5 );不起作用.

I'd like to know how to set a limit to your query running in Magento because $collection->getSelect()->limit( 5 ); doesn't work.

另外,如何随机选择$collection->setRandomOrder();也不起作用.

Also how to select randomly, $collection->setRandomOrder(); also doesn't work.

txs.

推荐答案

setRandomOrder不适用于产品集合,仅适用于相关产品.您必须使用以下代码自己添加它:

setRandomOrder does not work for collections of products, only for related products. You'll have to add it yourself with this code:

$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));

同时设置页面大小和页码的快捷方式是:

A shortcut for setting both page size and number at the same time is:

$collection->setPage($pageNum, $pageSize);

这篇关于通过rand()查询magento限制+订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆