I have 2 tables, tableA = notices and tableB = notice_receipts. I need to return all records from tableA based on tableA.user_type, which can be either ‘All’ or the users group.
THE CATCH: I don’t want to return the record if there is an entry in tableB, based on notice_id and user id.
I searched the internet and SO for examples. In fact, the below code is based off a SO answer. The problem is that tableA records are returned even if there is an entry in tableB.
$sql = "SELECT h.`id`, h.`message`
FROM `{$pdo->db_name}`.`notices` AS h
LEFT OUTER JOIN `{$pdo->db_name}`.`notice_receipts` AS d ON h.`id` = d.`notice_id` AND d.`viewed_user_id` = :user_id
WHERE h.`user_type` = :type OR h.`user_type` = 'All' AND d.`id` IS NULL
ORDER BY h.`posted_datetime` ASC, h.`title` ASC
;";
$pdo->query($sql);
$pdo->bind(":user_id", $_SESSION["user"]["id"]);
$pdo->bind(":type", str_ToUpper($_SESSION["user"]["sql_level"]));
Can anyone tell me where I messed up? If you need any more information just ask and I will post it.
Thanks for any and all help,
Charles