Magento addFieldToFilter常用过滤条件

//等于 Equals: eq  
$_products->addAttributeToFilter('status', array('eq' => 1));  
   
//不等于 Not Equals - neq  
$_products->addAttributeToFilter('sku', array('neq' => 'test-product'));  
   
//Like - like  
$_products->addAttributeToFilter('sku', array('like' => 'UX%'));  
   
//Not Like - nlike  
$_products->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));  
   
//In - in  
$_products->addAttributeToFilter('id', array('in' => array(1,4,98)));  
   
//Not In - nin  
$_products->addAttributeToFilter('id', array('nin' => array(1,4,98)));  
   
//NULL - null  
$_products->addAttributeToFilter('description', 'null');  
   
//Not NULL - notnull  
$_products->addAttributeToFilter('description', 'notnull');  
   
//大于 Greater Than - gt  
$_products->addAttributeToFilter('id', array('gt' => 5));  
   
//小于 Less Than - lt  
$_products->addAttributeToFilter('id', array('lt' => 5));  
   
//大于等于 Greater Than or Equals To- gteq  
$_products->addAttributeToFilter('id', array('gteq' => 5));  
   
//小于等于 Less Than or Equals To - lteq  
$_products->addAttributeToFilter('id', array('lteq' => 5));  

实例

$us_local_time = strtotime(Mage::getModel('core/date')->date());        
$banners = Mage::getModel('bannerslider/banner')->getCollection()
            ->addFieldToFilter('bannerslider_id', $id)
            ->addFieldToFilter('status', 0)
            ->addFieldToFilter('start_time', array('lteq' => $us_local_time))
            ->addFieldToFilter('end_time', array('gteq' => $us_local_time))
            ->setOrder('sort', "ASC");
        $banners->getSelect()->columns(array($randomise ? 'Rand() as order' : ''))->limit(5);
赞(0)
微信
支付宝
微信二维码图片

微信扫描二维码打赏

支付宝二维码图片

支付宝扫描二维码打赏

相关文章

Please Login to comment