10

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")
                                ->addFieldToFilter('customeremails',"'eq'=>$mail");

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

3 Answers 3

24

Try with below code,

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

Try following way:

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

No need to assign new variable again.

Debug:

echo $multiselect->count();
2

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

click

or simple in your case:

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

Your Answer

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

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