7

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.

17

Try with below code,

$multiselectupdate =$multiselect->getCollection()
                                ->addFieldToFilter('customergroup', ['eq' => $categoryname])
                                ->addFieldToFilter('customeremails',['eq' => $mail]);
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"]);
2

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();

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.