I trying to get output from collection using 'where' filter but no result. This is my code:
$collection = Mage::getModel('my_work/datanews')
->getCollection()
->getSelect()
->where('menu_id = ?', '1');
foreach ($collection as $item) {
echo $item->getData('collection');
}
What are the problems?
2 Answers 2
Try this:
$collection = Mage::getModel('my_work/datanews')
->getCollection()
->addFieldToFilter('menu_id', 1);
foreach ($collection as $item) {
echo $item->getData('content');
}
Note: If column collection exists on your collection, you should be able to use $item->getData('collection') as well.
Equals: eq
This is the default operator and does not need to be specified. Below you can see how to use the operator, but also how to skip it and just enter the value you're using.
$collection->addAttributeToFilter('menu_id', array('eq' => 1)); // Using the operator
$collection->addAttributeToFilter('menu_id', 1); // Without using the operator
answered Aug 19, 2019 at 4:38
Shafeel Sha
1,40516 silver badges34 bronze badges
default