与redbeanphp的交叉点

时间:2014-04-22 22:09:21

标签: php mysql redbean

我有一个$ $ mycontacts类型为$ contact

的bean

其中:

$contact->id = $x
$contact->name = $y
$contact->email= $z

我想检查$ mycontacts数组对第二个$ $联系的数组$。

我想执行$ mycontacts - $ contact以生成我未根据email参数联系的子集。现在我可以做类似

的事情
foreach ($mycontacts as $mycontact) {
     loop through $contacted and compare $contacted->email to $mycontact->email
}

使用php,redbean还是mysql有没有更好的方法呢?

1 个答案:

答案 0 :(得分:2)

$sql = 'SELECT * 
        FROM   contact
        WHERE  id NOT IN (SELECT mycontact.id
                          FROM   contact AS mycontact 
                          WHERE  1/* your condition*/)';
$rows = R::getAll( $sql );
$contactsMinusMyContacts = R::convertToBeans( 'contact', $rows );

此代码应该是性能最佳的,因为它几乎完全在数据库上运行,数据库是处理数据集的最佳位置。它首先选择所有联系人,然后减去"我的联系人"并返回结果。然后RedBean将它转换回bean。