我有问题,说明如何在我 below的提问中作案陈述。 基本上,问询只是从电文中提取电流,即把发送的当前用户(喷洒)或发送的原始透镜(翻新)发送。 这为每个人提供了完美的选任书,但原版的投稿人除外,他们应当能够拿到与透镜有关的所有信息。
Basically I need to add the SQL equivalent of the following statement:
WHERE messages_threads.id = $threadid
if($userid == messages_threads.senderid) {
// Don t add an AND clause
} else {
// Add the following AND clause
AND (messages_messages.senderid = $userid OR messages_messages.senderid = messages_threads.senderid)
}
Here s the query I m currently using:
SELECT messages_messages.id, messages_messages.senderid, username AS sendername, pictures.url AS picture, body, UNIX_TIMESTAMP(time) AS unixtimestamp
FROM messages_messages
JOIN messages_threads ON messages_threads.id = messages_messages.threadid
JOIN users ON messages_messages.senderid = users.id
LEFT JOIN pictures ON messages_messages.senderid = pictures.userid AND pictures.profile = 1
WHERE messages_threads.id = $threadid
AND (messages_messages.senderid = $userid OR messages_messages.senderid = messages_threads.senderid)
ORDER BY time ASC