Question

If i block a user my status is output more than once. Nobody else's, just mine.

If I block 3 users, my status update appears 3 times (the same status repeats). If I block 10 users, my status repeats 10 times.

This must be that bloody WHERE clause again... right?

//Get status results
        $sql = "SELECT 

        tbl_status.id as statID, 
        tbl_status.from_user as statFROM, 
        tbl_status.status as statSTATUS, 
        tbl_status.deleted as statDEL, 
        tbl_status.date as statDATE,

        tbl_users.id as usrID, 
        tbl_users.name as usrNAME,
        tbl_users.location as usrLOCATION,
        tbl_users.postcode as usrPOSTCODE,

        tbl_blocking.id as blockID,
        tbl_blocking.user as blockUSER,
        tbl_blocking.blocking as blockBLOCKING,
        tbl_blocking.date as blockDATE,
        tbl_blocking.block_by as blockBY,
        tbl_blocking.active as blockACTIVE

        FROM tbl_status 

        INNER JOIN tbl_users ON tbl_status.from_user = tbl_users.id
        LEFT JOIN tbl_blocking ON tbl_users.id = tbl_blocking.blocking

        WHERE 
        tbl_status.deleted = '0'
        AND tbl_blocking.user != :who
        OR tbl_blocking.user IS NULL

        ORDER BY 
        tbl_status.date desc

        LIMIT 200

        ";

No correct solution

OTHER TIPS

Your WHERE-condition mixes AND and OR, there's a precedence of evaluation, NOT - AND - OR

This is your current condition, adding brackets for clarity:

WHERE 
     (tbl_status.deleted = '0' AND tbl_blocking.user != :who)
  OR tbl_blocking.user IS NULL

You might want this intead:

WHERE 
      tbl_status.deleted = '0'
  AND (tbl_blocking.user != :who OR tbl_blocking.user IS NULL)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top