mercredi 5 août 2015

Filtering a MySQL query with multiple conditions


I have my output array named "Feed Items" (fi):

(
    [0] => Array
        (
            [reg] => 2015-08-03 13:39:00
            [id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
            [user_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
            [img] => edee88e88cf6e17732e393b5433cfd894662902e
            [type] => new_join_ambition
        )

)

I generate an array named "RemovedFeedItems" (rfi) that has the following structure:

(
    [0] => Array
        (
            [object_id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
            [postee_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
            [type] => new_join_ambition
        )

)

My mission is to not get the records that have the following condition:

ri.id == rfi.object_id && ri.user_id == rfi.postee_id && ri.type == rfi.type

The query that I use to get the Feed Items array is:

SELECT 
                i.registered AS reg, 
                a.id, 
                u.id AS user_id, 
                ui.image_id AS img,  
                'new_join_ambition' AS type, 
            FROM x_ambition_invites i 
                LEFT JOIN x_user u
                    ON i.to = u.id
                LEFT JOIN x_user_images ui 
                    ON u.id = ui.user_id
                LEFT JOIN x_ambitions a
                    ON i.ambition_id = a.id
            WHERE a.registered 
                BETWEEN '2014-07-21 14:25:03' AND '2015-08-05 12:04:41' 
            AND i.to != '8fa7a1679560876eaf2f8060abd916b692c719dc' 
            AND i.to IN ('de5fd44db1760b006b1909cf1db11a78b38e455c')

How can I adapt my query to implement the condition to remove the stated record from the FeedItems Array?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire