magento select multiple coloumn with like attribute from a table using magento query colelction
If I want to select a value from 2 or more columns i will use the below code in magento collection
$collection = Mage::getModel('module/module')->getCollection()->addAttributeToSelect('*')->addFieldToFilter(array(0=>'col1',1=>'col2'),array(0=>array('like' => '%'.$cond.'%'),1=>array('like' => '%'.$cond.'%')));
The result
SELECT `main_table`.`*` FROM `table` AS `main_table` WHERE (((col1 like '%cond%') or (col2 like '%cond%')))
No comments:
Post a Comment