1

enter image description here

enter image description here

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

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.

answered Aug 19, 2019 at 1:44
0

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

Learn More about Attribute filter condition

answered Aug 19, 2019 at 4:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.