addFieldToFilter() And Condition in magento2

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.


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 with below code,

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

Try following way:

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

No need to assign new variable again.


echo $multiselect->count();

Similar questions

if statement attribute condition & categories condition (2 conditions)
I have a large amount of products, about half do not have a proper description. To address this I've created an if statement that will display the product name one way and if the condition is not met then it will display it another. Example: Now, I'd like to go a step further with the above rule and set it so that if the product_updated attribute i...
How to add validate() new condition in module-sales-rule/Model/Rule/Condition/Address.php?
Need to add new condition in validate() function of module-sales-rule/Model/Rule/Condition/Address.php by overriding this class in custom module. This function is called on checkout page in frontend when cart price rule is applied via 'Free Shipping' I have tried using both preference & plugin but both not working Please advice, It will be real...
Magento Shopping Cart Rule Condition - Custom condition quote id
I want dynammically create a shopping cart rule to apply to particular quote id. Any suggestion to do that?
convert sql query to magento addFieldToFilter combine OR and AND
You can convert me this sql I did not arrive at combined OR and AND at the same time SELECT * FROM sales_order AS main_table, sales_order_payment AS sop WHERE ((status = 'processing') Or ((status = 'pending') and (sop.method = 'chekmo') )) AND (updated_at >= '2020-06-19 18:24:59') Please, can someone help or suggest anything?
How to use addFieldToFilter & addFieldToSelect in magento2
I need to known how to use addFieldToFilter & addFieldToSelect in frontend? And can I use like below
Magento2 addFieldToFilter call works with hardcoded value but not variable with same value
I'm building the admin for a Magento2 store (currently on 2.1.7, they want to use the newest version until we go live and then want to stabilize a particular version). The module in question is supposed to display all existing orders, with an actionsColumn that contains links to cancel, edit, and open a detailed overview of the purchased items asso...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.