Guru Salem Posted July 12, 2012 Posted July 12, 2012 $compoundFind =& $fm->newCompoundFindCommand('Accounts'); $findreq1 =& $fm->newFindRequest('Accounts'); $findreq2 =& $fm->newFindRequest('Accounts'); $findreq1->addFindCriterion('acctype', 'User'); $findreq2->addFindCriterion('squestion', '1'); $compoundFind->add(1,$findreq1); $compoundFind->add(2,$findreq2); $result = $compoundFind->execute(); When i use the above compoundfind, I found all the records where the acctype=User also squestion=1 But i need the the records where acctype=User and squestion=1 (refer attached image: I need 2 records only which is marked in green color) Please help me to alter the above find code to attain my solution
doughemi Posted July 12, 2012 Posted July 12, 2012 Compound Find requests perform an or search (Criterion1 OR Criterion2). You only need the normal newFindCommand to perform an and search (Criterion1 AND Criterion2): $findreq =& $fm->newFindCommand('Accounts'); $findreq->addFindCriterion('acctype', 'User'); $findreq->addFindCriterion('squestion', '1'); $result = $findreq->execute();
Guru Salem Posted July 16, 2012 Author Posted July 16, 2012 Thank u doughemi, With this same case how do i get the records where the acctype="User" and acctype="Family" ? That means i have to filter more than one data from the single column. Thanks your valuable reply and valuable time
doughemi Posted July 16, 2012 Posted July 16, 2012 In this case, you are looking to find records in which acctype="User" OR acctype ="Family". (it is impossible in this instance to have a record in which acctype contains both "User" AND "Family"). Thus, you would use the Compound Find structure: $compoundFind =& $fm->newCompoundFindCommand('Accounts'); $findreq1 =& $fm->newFindRequest('Accounts'); $findreq2 =& $fm->newFindRequest('Accounts'); $findreq1->addFindCriterion('acctype', 'User'); $findreq2->addFindCriterion('acctype', 'Family'); $compoundFind->add(1,$findreq1); $compoundFind->add(2,$findreq2); $result = $compoundFind->execute(); I would recommend that you research "Boolean AND and OR operators" to build your understanding of these important tools. These operators have much more specific definitions than the common usage of the English words they are based on. Now, if you were conducting a search for records which have either "User" or "Family" in the acctype field and at the same time have 1 in the squestion field, you would have to expand the Compound Find structure: $compoundFind =& $fm->newCompoundFindCommand('Accounts'); $findreq1 =& $fm->newFindRequest('Accounts'); $findreq2 =& $fm->newFindRequest('Accounts'); $findreq1->addFindCriterion('acctype', 'User'); $findreq1->addFindCriterion('squestion', '1'); $findreq2->addFindCriterion('acctype', 'Family'); $findreq2->addFindCriterion('squestion', '1'); $compoundFind->add(1,$findreq1); $compoundFind->add(2,$findreq2); $result = $compoundFind->execute();
Recommended Posts
This topic is 4780 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now