我一直在尝试为很久以前为论坛制作的个人资料墙脚本编写通知系统。我遇到的麻烦是,我试图只向符合 PM 标准的人发送一个 PM,但我在 MYSQL 中也有 2 个选择语句来找到应该被 PM 的人。
我有2张桌子可供选择... log_statuses
和log_status_replies
我正在努力实现这一目标。我希望它通知所有只发表过一次评论的人!还有它所属的人墙和在人物墙上写状态的人,但如果你写了它,不是你自己。有点复杂,这就是为什么我正在努力做到这一点......
这是我的代码,用于搜索谁发表了评论并向他们发送 PM。我还将如何检查谁写了状态以及谁的墙,如果他们也发表了评论,它就不会发送重复的 PM。
否则,他们会收到一个 PM,因为他们已经发表了评论,并且因为它的状态/墙。我希望你明白这一点,有点难以解释。
这是我的源代码。我会喜欢任何能提供帮助的人。
$query = $smcFunc['db_query']('', '
SELECT id_member, id_poster
FROM {db_prefix}log_statuses
WHERE id_status = {int:id_status}',
array(
'id_status' => $status,
)
);
list($id_member,$id_poster) = $smcFunc['db_fetch_row']($query);
if ($id_poster != $ucomment || $id_member != $ucomment)
{
$query2 = $smcFunc['db_query']('', '
SELECT DISTINCT id_member
FROM {db_prefix}log_status_replies
WHERE id_status = {int:id_status}',
array(
'id_status' => $status,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query2)) {
if ($row['id_member'] != $ucomment)
{
$pm_recipients = array(
'to' => array($row['id_member']),
'bcc' => array(),
);
require_once($sourcedir . '/Subs-Post.php');
$notify_body = $txt['status_body'] . '[iurl]' .$scripturl . '?action=profile;area=showstatus;s=' . $status . '[/iurl]';
$notify_body = str_replace("%poster",$context['user']['name'],$notify_body);
$pm_from = array(
'id' => $ucomment,
'username' => '',
'name' => '',
);
sendpm($pm_recipients,$txt['status_subject'] , $notify_body,false,$pm_from);
}
}
}
$id_member是人物墙,$id_poster是张贴在墙上的人。$ucomment是发帖的人。
已解决。我从 while 构建了一个数组,然后在检查另一个表以查看谁也 PM 时检查注释表中是否存在该值。.
$id_comment = array();
while ($row = $smcFunc['db_fetch_assoc']($query2)) {
$id_comment[] = $row['id_member'];
}
if (!in_array($id_poster, $id_comment) && !in_array($id_member, $id_comment)) {
//Send PM
}
使用 UNION
:
例如::
Select column1 from table1 where condition1=true
UNION
Select column1 from table1 where condition2=true
结果集不会有重复的记录。
碰巧,如果您需要包括重复项在内的所有值,请使用UNION ALL