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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.