I need to filter values based on and condition in my custom table

my tablename Testing

 | customer_id | customergroup      | customeremails     |

if customergroup and customeremails same means I dont add this value

so, I put this condition:

   $multiselectupdate =$multiselect->getCollection()
                                ->addFieldToFilter('customergroup', "'eq'=>$categoryname")

But, its not working for Suggest me How set And Condition in addFieldToFilter() method.


Try with below code,

$multiselectupdate =$multiselect->getCollection()
                                ->addFieldToFilter('customergroup', ['eq' => $categoryname])
                                ->addFieldToFilter('customeremails',['eq' => $mail]);

Here is the solution for you to understand how Magento 2 use query operators to filter with addFieldToFilter


or simple in your case:

$multiselectupdate->addFieldToFilter('customergroup', ['eq' => "$categoryname"]);

Try following way:

->addFieldToFilter('customergroup', array('eq'=>$categoryname))

No need to assign new variable again.


echo $multiselect->count();

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.