我有一个SQL查询:
SELECT r.*, t.title, t.active, ticket_author.username as ticket_author, responser.username, responser.isAdmin, responser.isMod
FROM `support_tickets_replies` r
LEFT JOIN `support_tickets` t ON (t.id = r.tid)
LEFT JOIN `users` ticket_author ON (ticket_author.id = t.uid)
LEFT JOIN `users` responser ON (responser.id = r.uid)
WHERE r.tid = [something goes here]
我必须检查,该票证是否属于当前用户。用户ID位于t.uid
。当它不是那个用户时,只返回“错误”列,并显示消息“禁止”。只能使用MySQL吗?
答案 0 :(得分:1)
SELECT r.*, t.title, t.active, ticket_author.username as ticket_author, responser.username, responser.isAdmin, responser.isMod
FROM `support_tickets_replies` r
LEFT JOIN `support_tickets` t ON (t.id = r.tid)
LEFT JOIN `users` ticket_author ON (ticket_author.id = t.uid)
LEFT JOIN `users` responser ON (responser.id = r.uid)
WHERE r.tid = [something goes here]
AND t.uid = [User ID goes here]
此查询仅会显示属于该用户的记录。 如果记录不属于用户,则不会返回任何内容。